Initialization of Upgradeable Contract Not Working

I'm trying to deploy an upgradeable contract. When I use hardhat to deploy locally, the initialization works fine. When I use hardhat to deploy on rinkeby, the name and owner are empty. I've read lots of posts on here, but can't find a solution. Help please? Thank you.

Here's my code:

import '@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol';
import '@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721BurnableUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol';
import '@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol';
import './Base64.sol';

contract Burger is 
    Initializable,
    ERC721Upgradeable,
    ERC721EnumerableUpgradeable,
    ERC721URIStorageUpgradeable,
    PausableUpgradeable,
    OwnableUpgradeable,
    ERC721BurnableUpgradeable,
    ReentrancyGuardUpgradeable
{

    using CountersUpgradeable for CountersUpgradeable.Counter;

    CountersUpgradeable.Counter private _tokenIdCounter;

    struct Burg {
            address recipientAddress;
            address providerAddress;
            string name;
    }

    uint256 public price;

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() initializer {}

    function initialize() initializer public {
        __ERC721_init("Burger", "BURG");
        __ERC721Enumerable_init();
        __ERC721URIStorage_init();
        __Pausable_init();
        __Ownable_init();
        __ERC721Burnable_init();

        price = 0.001 ether;
    }

Also, here's my deploy script:

async function main() {
  const Contract = await ethers.getContractFactory('Burger');
  console.log('Deploying...');
  const contract = await upgrades.deployProxy(Contract);
  await contract.deployed();
  console.log('Deployed to:', contract.address);
}

main()
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });

I tried changing my inits to have _unchained at the end, but that didn't help.

Thanks for any help.

Hi @jared, can you ensure you are checking the proxy address, not the implementation address on Rinkeby? You can also try adding this to your deploy script:

  console.log("name: ", await contract.name());
  console.log("owner: ", await contract.owner());
1 Like

Hey, thanks so much for the guidance. Those console.log statements do work properly in the deploy script, so that's good!

Here are examples of the deployed contracts. I need to run tasks on my contract that I wrote as the owner, and the contract that I wrote is the only one with the owner and name functions. Am I misunderstanding how this works?

You're totally right. I see now that I was checking the implementation address not the proxy address. So it looks like I can't use the implementation contract for anything, and I can't use the proxy contract through a block explorer. So, I have to use my local environment to interact with the proxy contract, and only the proxy contract?

The proxy has its own state but uses your implementation contract as its logic. In other words, the implementation contract's code is run in the context of the proxy, so the implementation contract's own state is irrelevant.

In order to interact with the proxy directly through Etherscan, you need to flag it as a proxy on Etherscan. See https://medium.com/etherscan-blog/and-finally-proxy-contract-support-on-etherscan-693e3da0714b

1 Like

You're my hero! Thank you so much for the help. After 8 hours of wrestling with this, a few minutes of your guidance saved me another 8 hours.

1 Like