`oz deploy` `initialize` fails with Error: Returned error: gas required exceeds allowance (80000000) or always failing transaction

Hello @mmurthy , can i know what you did eventually (Error: gas required exceeds allowance (8000000) or always failing transaction)?
I’m having the same issue with an upgradeable contract and it throws the above error with the initialize function itself! sad to know that the problem has yet not been resolved!

Here’s the log:

? Choose the kind of deployment upgradeable
? Pick a network testnet
? Pick a contract to deploy Dice
✓ Contract Dice deployed
All implementations have been deployed
? Call a function to initialize the instance after creating it? Yes
? Select which function * initialize()
✖ Creating instance for contract at 0xF48bC8a7a39cB34c4a8C0e816CA808B79eF2e5A3 and calling 'initialize' with no arguments

Error: Returned error: gas required exceeds allowance (80000000) or always failing transaction

my initialize function only assigns the sender as manager and is payable!

1 Like

Hi @asmeedhungana,

It sounds like your initialize function is reverting. Which is different from the issue reported here: Error: gas required exceeds allowance (8000000) or always failing transaction

Are you able to share your smart contract (or a cut down version)?

Otherwise I suggest that you deploy as a regular contract to a local testnet and then use oz send-tx to call initialize to see if this transaction fails.

sure! Thanks…i’ll try that and still if the error persists, then I’ll share the contract’s snip.

1 Like

Hi @asmeedhungana,

Were you able to find the issue in the initialize function?

Hey @abcoathup,
I haven’t been able to look nicely at it because I thought, well… to know it from the bones, i need to know eth about upgradeable contracts!
However, I tested it for Rinkeby and it worked just fine! I was able to deploy it as regular and even upgradeable and could use its other functions too! For harmony however, it was the same…

Here’s the address of the deployed contract instance on Rinkeby:
Rinkeby upgradeable: 0xB9CE4120F4e2683E2025723C6fa40EE53d90b086

1 Like

Hi @asmeedhungana,

Did the deploy only fail when deploying to Harmony blockchain?

If so, I would check what EVM versions Harmony supports as this could be the cause of the issue.

It happens when I call initialize while deploying the contract in rinkeby ntk too! Here’s the log:

asmee@asmee:/media/asmee/H/fix-test$ npx oz upgrade
? Pick a network rinkeby
? Which instances would you like to upgrade? Choose by address
? Pick an instance to upgrade Dice at 0xB9CE4120F4e2683E2025723C6fa40EE53d90b086
? Call a function on the instance after upgrading it? Yes
? Select which function * initialize()
✓ Compiled contracts with solc 0.6.10 (commit.00c0fcaf)
Compilation warnings:
@openzeppelin/upgrades/contracts/Initializable.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: " to each source file. Use “SPDX-License-Identifier: UNLICENSED” for non-open-source code. Please see https://spdx.org for more information.

contracts/Migrations.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: " to each source file. Use “SPDX-License-Identifier: UNLICENSED” for non-open-source code. Please see https://spdx.org for more information.

  • New variable ‘uint256 versionTwo’ was added in contract Dice in contracts/Dice.sol:1 at the end of the contract.
    See https://docs.openzeppelin.com/upgrades/2.6//writing-upgradeable#modifying-your-contracts for more info.
    ✓ Contract Dice deployed
    All implementations have been deployed
    :heavy_multiplication_x: Upgrading instance at 0xB9CE4120F4e2683E2025723C6fa40EE53d90b086 and calling ‘initialize’ with no arguments
    :heavy_multiplication_x: Upgrading instance at 0xB9CE4120F4e2683E2025723C6fa40EE53d90b086
    Proxy dice-contract/Dice at 0xB9CE4120F4e2683E2025723C6fa40EE53d90b086 failed to upgrade with error: Error: gas required exceeds allowance (10000000) or always failing transaction
1 Like

Hi @asmeedhungana,

When we first deploy an upgradeable contract, instead of using a constructor we use an initialize function which should have a guard to ensure it is only called once.

When we upgrade a contract, if we need to set any state, we need to create a function to set any state, we can call this function whatever we like e.g. upgradeV1. This function should be guarded so that it can only be called once. The guard could be checking if state variables are initialized or we could have a new state variable to check if our upgrade has been initialized.

It looks like you are trying to call an initialize when doing an upgrade. Assuming that the initialize function uses the initializer modifier, then this can only be called once. So it will revert during your upgrade if you try to call this again.

See Initialization for more details.

1 Like

Hmmm… This had come across my mind, but since I was thinking that Initialize can be called even when nth in it has been changed for every upgrade, i called it while upgrading!

I only wish the error messages were clearer…
However, thanks for your help, as always! :smiley:

1 Like