0

I've been trying to run an onlyOwner function in Ganache-cli, but I keep getting this error, even though migrated the contract a minute earlier and didn't change the owner. This the first test since switching over to upgradeable erc721, so is there something in the upgradeable contracts that would cause this behavior?

contract:

//Contract based on [https://docs.openzeppelin.com/contracts/3.x/erc721](https://docs.openzeppelin.com/contracts/3.x/erc721)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "../node_modules/@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import "../node_modules/@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol";
import "../node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "../node_modules/@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol";
import "../node_modules/@openzeppelin/contracts-upgradeable/token/common/ERC2981Upgradeable.sol";

contract Redacted is ERC721URIStorageUpgradeable, OwnableUpgradeable, ERC2981Upgradeable {
    using CountersUpgradeable for CountersUpgradeable.Counter;
    CountersUpgradeable.Counter private _tokenIds;

    function initialize() initializer public {
         __ERC721_init("Redacted", "RED"); 
         }
        

    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Upgradeable, ERC2981Upgradeable) returns (bool) {
        return
            interfaceId == type(IERC721Upgradeable).interfaceId ||
            interfaceId == type(IERC721MetadataUpgradeable).interfaceId || 
            interfaceId == type(IERC2981Upgradeable).interfaceId ||
            super.supportsInterface(interfaceId) ;
    }


    function mintNFT(address recipient, string memory tokenURI)
        public onlyOwner
        returns (uint256)
    {
        _tokenIds.increment();

        uint256 newItemId = _tokenIds.current();
        _mint(recipient, newItemId);
        _setTokenURI(newItemId, tokenURI);

        return newItemId;
    }

    function setDefaultRoyalty(address receiver, uint96 feeNumerator) public onlyOwner {
      _setDefaultRoyalty(receiver, feeNumerator);
    }

    function setTokenRoyalty(uint256 tokenId, address receiver, uint96 feeNumerator) public onlyOwner {
        _setTokenRoyalty(tokenId, receiver, feeNumerator);
    }
}

deployment 1:

const Migrations = artifacts.require("Migrations");

module.exports = function (deployer) {
  deployer.deploy(Migrations);
};

Deployment 2:

const Redacted = artifacts.require("Redacted");


module.exports = async function(deployer){
  await deployer.deploy(Redacted);
}

Deployment 3:

const { deployProxy } = require('@openzeppelin/truffle-upgrades');

const AlmaNFT = artifacts.require('Redacted');

module.exports = async function(deployer){
    await deployer.deploy(Redacted);
  }
2
  • 1
    Can you share the contract and deployment script?
    – 0xSanson
    Commented Sep 24, 2022 at 21:01
  • added. see above
    – Antheloth
    Commented Oct 2, 2022 at 22:37

1 Answer 1

0

Figured it out, I didn't have __Ownable_init() in the initializer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.