Ownable set to 0 address

Using this same method on the new upgradable libs I get an error message. Could you help me out with this? In fact I’m having a lot of issues using the ‘Extensions’…

....
import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

contract MyContract is ERC721Upgradeable, OwnableUpgradeable {
    function initialize() public initializer {
        __ERC721_init("MyNFT", "NFT");
        OwnableUpgradeable.initialize(msg.sender);
    }
}

But I get this error:

I also had some trouble including the totalSupply() function from another extension. Any help would be appreciated thank you.

UPDATE - Nervermind, got it to work with OwnableUpgradeable.__Ownable_init();. My mistake.

Another update Calling owner() still returns me 0x0000000000000000000000000000000000000000, I want to cry.

1 Like

Hi @RRomjon,

Welcome to the community :wave:

To use OpenZeppelin Contracts with upgrades with multiple inheritance we can call the __{ContractName}_init_unchained functions. See documentation: https://docs.openzeppelin.com/contracts/4.x/upgradeable

See the example in this forum post:

Hey,

Thanks for the reply. I have tried this out and I am still receiving 0 address from owner();

import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol";

contract MyContract is ERC721Upgradeable, OwnableUpgradeable {
    using CountersUpgradeable for CountersUpgradeable.Counter;
    CountersUpgradeable.Counter private _tokenIds;

    function initialize() public initializer {
        __ERC721_init_unchained("MyNFT", "NFT");
        __Ownable_init_unchained();
    }

}
1 Like

Oh nooo!!! It was my deployment code, I just had a look at it and I had specifically set the initializer to one of my functions!

I was following this guide https://docs.openzeppelin.com/learn/upgrading-smart-contracts and my deploy proxy code was doing something like this:

 const box = await upgrades.deployProxy(Box, [42], { initializer: 'store' });

I changed it to just deploy the actual contract so looking more like this so it would actually run my initializer method!!

 const box = await upgrades.deployProxy(Box);

I shouted ‘YES’ after seeing this.
image

Thank you very much.

1 Like

Hi @RRomjon,

Glad you were able to resolve!

I tried to keep the example as simple as possible, by not creating an explicit initialize function and just reused store. Sorry if this tripped you up.

1 Like

It’s no worries, I kind of thought it was like a C# class where the constructor/initialize method occurred before the store function. I should’ve looked at that earlier myself to be honest. Thank you for the help, it’s reassuring to know that this library is backed by such an active community.

1 Like

This is old, but I also got tripped up on this.

The tutorial using the 'store' function as an initializer is shorter, but not as clear.