Issue during OpenZeppelin Upgrade - Step by Step Tuto with Hardhat

Hi Guys, it’s my first post on OpenZeppelin, amazing library and forum looks cool. :slight_smile:

:computer: Environment
Hardhat OpenZeppelin Upgrades Plugin - Node.js v14.16.1 - BSC TestNet - Hardhat v2.2.1 - MetaMask - Windows 10 20H2, package.json below:

"devDependencies": {
    "@nomiclabs/hardhat-ethers": "^2.0.2",
    "@openzeppelin/hardhat-upgrades": "^1.7.0",
    "chai": "^4.3.4",
    "ethers": "^5.1.4",
    "hardhat": "^2.2.1"
  }

:memo:Details
I tried to follow the tutorial, all passed successfully but after upgrade Box with BoxV2, I tried to interact with new contract (code to reproduce is below). Note that I don’t migrate ownership to Gnosis Safe. I know I made a mistake but if someone could help me, it will be very helpful, thanks ! ^^

:1234: Code to reproduce

> (await boxV2.retrieve()).toString()
'42'

But increment function doesn’t work:

> await boxV2.increment()

Result:

reason: 'cannot estimate gas; transaction may fail or may require manual gas limit',
  code: 'UNPREDICTABLE_GAS_LIMIT',
  error: ProviderError: execution reverted

So tried this, with GasLimit argument:

> await boxV2.increment({gasLimit: 250000})

Result:

{
  hash: '0x95f0ef4ed4a38174153297356b1d4bf1e680d987b14278a287a53bc53ae3db28',
  type: 0,
  accessList: null,
  blockHash: null,
  blockNumber: null,
  transactionIndex: null,
  confirmations: 0,
  from: '0x7515Ee924039f2DB08fcfa2fD94325c2c4403706',
  gasPrice: BigNumber { _hex: '0x02540be400', _isBigNumber: true },
  gasLimit: BigNumber { _hex: '0x03d090', _isBigNumber: true },
  to: '0x84A97E1002c858c5C5E4363789B5F51bF1Db7F42',
  value: BigNumber { _hex: '0x00', _isBigNumber: true },
  nonce: 4,
  data: '0xd09de08a',
  r: '0xe88dabfcb8ff06cde7197b91e0738ac50d9c89e702d4f4c8b58b60884556f364',
  s: '0x15eefb1ae021b529f37adcba94d438e6bc11caa6bd823e23505f543bd93e41eb',
  v: 229,
  creates: null,
  chainId: 97,
  wait: [Function (anonymous)]
}

And stored value doesn’t increment after new check, you will find below txID on the BSC TestNet blockchain:

Tried again after verified contract on BSC TestNet with increment function included gasLimit argument and obtain this:

You can find also the two files inside “.openzeppelin” subfolder:

  • First one named “unknow-97.json”:
{
  "manifestVersion": "3.2",
  "impls": {
    "a65cdfa308566facef6065beb9e631bc7782c0699e2093fd7f5bc24c50583bce": {
      "address": "0x0d087e51d55f292C5BA5892Db83C5F82223196B2",
      "txHash": "0x930342b77eafa7c8642ec304c27ea1ce17723c1d6ad934c03af063a60d522b57",
      "layout": {
        "storage": [
          {
            "contract": "Box",
            "label": "value",
            "type": "t_uint256",
            "src": "contracts\\Box.sol:6"
          }
        ],
        "types": {
          "t_uint256": {
            "label": "uint256"
          }
        }
      }
    },
    "a8c34e30dd42bfa0d900135a30dbc42f877332f6d3aa29d69727e5d34d15e657": {
      "address": "0xFA14f025993fF4ccA667d92dFa7FfBADDd0960E3",
      "txHash": "0x1c4f275826ddcf8fee0507c09d368b5b74daf1138814895007446de51e8be009",
      "layout": {
        "storage": [
          {
            "contract": "BoxV2",
            "label": "value",
            "type": "t_uint256",
            "src": "contracts\\BoxV2.sol:6"
          }
        ],
        "types": {
          "t_uint256": {
            "label": "uint256"
          }
        }
      }
    }
  },
  "proxies": [
    {
      "address": "0x84A97E1002c858c5C5E4363789B5F51bF1Db7F42",
      "kind": "transparent",
      "txHash": "0x2c35484c43c9335ed0a633b46fc66ccc24aeb877267c72f47029f699ba80c4be"
    }
  ],
  "admin": {
    "address": "0xf2C4F6CA2EFb42AD891304dD4Daa474F88e23eBc",
    "txHash": "0x7ad6fae0115f7596f8462ca9c5dab9835c925c82832802a12bcfbf1a16b062e9"
  }
}

And second one named “unknow-31337.json”:

{
  "manifestVersion": "3.2",
  "impls": {
    "a65cdfa308566facef6065beb9e631bc7782c0699e2093fd7f5bc24c50583bce": {
      "address": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
      "txHash": "0x4997300c5a61a30e81d77ba198d3ab5ff646eb4b21c272f6195227973359174c",
      "layout": {
        "storage": [
          {
            "contract": "Box",
            "label": "value",
            "type": "t_uint256",
            "src": "contracts\\Box.sol:6"
          }
        ],
        "types": {
          "t_uint256": {
            "label": "uint256"
          }
        }
      }
    },
    "a8c34e30dd42bfa0d900135a30dbc42f877332f6d3aa29d69727e5d34d15e657": {
      "address": "0x610178dA211FEF7D417bC0e6FeD39F05609AD788",
      "txHash": "0xf94dc6a8412f34b7b381e8b9bce26d7e5ab17400a5238886c88ce69fd2e84c6e",
      "layout": {
        "storage": [
          {
            "contract": "BoxV2",
            "label": "value",
            "type": "t_uint256",
            "src": "contracts\\BoxV2.sol:6"
          }
        ],
        "types": {
          "t_uint256": {
            "label": "uint256"
          }
        }
      }
    }
  },
  "proxies": [
    {
      "address": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
      "kind": "transparent",
      "txHash": "0x34d0cadf699a798f3ce528b670111327982958b13adf359045922609effc7aac"
    },
    {
      "address": "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
      "kind": "transparent",
      "txHash": "0x77d2abd3f90c988d84f6c1af8b9123a362b6ab98b31b9fccb6586566ec7396c4"
    }
  ],
  "admin": {
    "address": "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
    "txHash": "0x8939ff5fc58396f18184c8aa25d7a191f36dbd0792f1bda4557ff42547b7f0b6"
  }
}

Trying to redo all process inside new folder and the same file "unknow-31337.json inside “.openzeppelin” subfolder was created after the command “npx hardhat test” on Box.sol contract. So, first file “unknow-97.json” corresponding to my test on BSC TestNet.

I followed the tutorial of abcoathup, same issue, doesn’t work on my side. :’(

Here my hardhat.config.js:

// hardhat.config.js
const { mnemonic } = require('./secrets.json');

require("@nomiclabs/hardhat-ethers");
require('@openzeppelin/hardhat-upgrades');

/**
 * @type import('hardhat/config').HardhatUserConfig
 */
module.exports = {
  solidity: "0.7.3",
  networks: {
    bsctestnet: {
      url: `https://data-seed-prebsc-1-s1.binance.org:8545`,
      accounts: {mnemonic: mnemonic}
    }
  }
};

Thanks in advance.

1 Like

Hi @mikroub welcome to the Open Zeppelin Forums!

You’re very close to getting it to work.

Following the steps exactly should work as intended.
Do the Gnosis Safe part so you can learn that. It is a fantastic tool and it is free if you use Rinkeby.

I highly Recommend Rinkeby instead of BSCtestnet. You can use Uniswap V2 for Pancake Swap testing.

When you swap to mainnet BSC, Gnosis Safe works for BSC mainnet so no worries there.

Hi @Yoshiko, many thanks for your feedback. :pray:

I will check under Rinkeby like you said. Effectively, actual use Remix IDE and Ganache to test it on local node, to finally deploy contracts on BSC TestNet to check on public testnet node. OpenZeppelin and Hardhat are news on my side, I will check with Rinkeby, don’t know that it will possible to check pancake swap under this node, good info, thanks. :slightly_smiling_face:

Have you got a link to some documentation about PancakeSwap? I think, I need to use a special router address for testing swap and docs on PancakeSwap are very poor, so I actually read documentation on UniSwap. :man_shrugging:

Have a good day. :wave:

Sadly PancakeSwap does not have good documentation. https://docs.pancakeswap.finance/

But you can learn a lot from Uniswap. PCS is basically Uniswap V2 with minor tweaks.