Ownable: caller is not the owner with ERC1155 contract from the Contract Wizard

Hi I created a 1155 contract via the Wizard. It keeps getting "Ownable: caller is not the owner" error on remix when I'm trying to run the mint function. No modification to the code yet; just using the boilerplate code from the Wizard.

Below is the code. Thanks.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155SupplyUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

contract MyToken is Initializable, ERC1155Upgradeable, OwnableUpgradeable, PausableUpgradeable, ERC1155BurnableUpgradeable, ERC1155SupplyUpgradeable, UUPSUpgradeable {
    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() initializer {}

    function initialize() initializer public {
        __ERC1155_init("");
        __Ownable_init();
        __Pausable_init();
        __ERC1155Burnable_init();
        __ERC1155Supply_init();
        __UUPSUpgradeable_init();
    }

    function setURI(string memory newuri) public onlyOwner {
        _setURI(newuri);
    }

    function pause() public onlyOwner {
        _pause();
    }

    function unpause() public onlyOwner {
        _unpause();
    }

    function mint(address account, uint256 id, uint256 amount, bytes memory data)
        public
        onlyOwner
    {
        _mint(account, id, amount, data);
    }

    function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
        public
        onlyOwner
    {
        _mintBatch(to, ids, amounts, data);
    }

    function _beforeTokenTransfer(address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
        internal
        whenNotPaused
        override(ERC1155Upgradeable, ERC1155SupplyUpgradeable)
    {
        super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
    }

    function _authorizeUpgrade(address newImplementation)
        internal
        onlyOwner
        override
    {}
}

@Patrick_Chan did you get any workaround for this problem?

The contract above is an upgradeable one, designed to be used with a proxy.

If you deploy it like that, you won't be able to use it directly. You then need to deploy a proxy that points to it, and initialize the proxy (by calling initialize()). Only then will you be able to mint (on the proxy)

1 Like

@Amxx Yes, you're right. I needed to use ERC1967Proxy along with ERC1155Upgradable smart contract. I needed to deploy the ERC1155Upgradable first as the logic contract and then needed to use the address of deployed logic contract to deploy ERC1967Proxy as proxy contract.
After the initialization of proxy contract, we can perform all the operations of the logic contract via this proxy contract and we can now use upgradeTo method to upgrade to a newer version of the logic contract.