Error initializing upgradeable contract: insufficient funds for gas * price + value

Hi

I deployed my contract but when I called initialize method got this error:

Choose the kind of deployment upgradeable
? Pick a network mainnet
? Pick a contract to deploy CrToken
√ Contract CrToken deployed
All implementations have been deployed
? Call a function to initialize the instance after creating it? Yes
? Select which function * initialize()
× Setting everything up to create contract instances
insufficient funds for gas * price + value

Now I cant call my mehtods again

How I can config files for contract address?

I get this error

oz call
? Pick a network mainnet
A contract address must be specified.

mainnet.json:

{
  "contracts": {
    "CrToken": {
      "address": "0xD733860828662e09fB96b459960B22ba0F39C66C",
      "constructorCode": "608060405234801561001057600080fd5b506133c0806100206000396000f3fe",
      "bodyBytecodeHash": "050043ea81df5b4ae43817bac30f13bff2ee49a847b295a143e0e5e223f4a16f",
      "localBytecodeHash": "cc454b14008e001792c9e897d142bb047756b06f7d7d0c0a48d54d1dde705557",
      "deployedBytecodeHash": "cc454b14008e001792c9e897d142bb047756b06f7d7d0c0a48d54d1dde705557",
      "types": {
        "t_bool": {
          "id": "t_bool",
          "kind": "elementary",
          "label": "bool"
        },
        "t_uint256": {
          "id": "t_uint256",
          "kind": "elementary",
          "label": "uint256"
        },
        "t_array:50<t_uint256>": {
          "id": "t_array:50<t_uint256>",
          "valueType": "t_uint256",
          "length": "50",
          "kind": "array",
          "label": "uint256[50]"
        },
        "t_struct<AccessControlUpgradeSafe.RoleData>": {
          "id": "t_struct<AccessControlUpgradeSafe.RoleData>",
          "kind": "struct",
          "label": "AccessControlUpgradeSafe.RoleData",
          "members": [
            {
              "label": "members",
              "astId": 201,
              "type": "t_struct<EnumerableSet.AddressSet>",
              "src": "1655:32:3"
            },
            {
              "label": "adminRole",
              "astId": 203,
              "type": "t_bytes32",
              "src": "1697:17:3"
            }
          ]
        },
        "t_struct<EnumerableSet.AddressSet>": {
          "id": "t_struct<EnumerableSet.AddressSet>",
          "kind": "struct",
          "label": "EnumerableSet.AddressSet",
          "members": [
            {
              "label": "_inner",
              "astId": 1981,
              "type": "t_struct<EnumerableSet.Set>",
              "src": "4644:10:12"
            }
          ]
        },
        "t_struct<EnumerableSet.Set>": {
          "id": "t_struct<EnumerableSet.Set>",
          "kind": "struct",
          "label": "EnumerableSet.Set",
          "members": [
            {
              "label": "_values",
              "astId": 1797,
              "type": "t_array:dyn<t_bytes32>",
              "src": "1213:17:12"
            },
            {
              "label": "_indexes",
              "astId": 1801,
              "type": "t_mapping<t_uint256>",
              "src": "1364:37:12"
            }
          ]
        },
        "t_bytes32": {
          "id": "t_bytes32",
          "kind": "elementary",
          "label": "bytes32"
        },
        "t_array:dyn<t_bytes32>": {
          "id": "t_array:dyn<t_bytes32>",
          "valueType": "t_bytes32",
          "length": "dyn",
          "kind": "array",
          "label": "bytes32[]"
        },
        "t_mapping<t_uint256>": {
          "id": "t_mapping<t_uint256>",
          "valueType": "t_uint256",
          "label": "mapping(key => uint256)",
          "kind": "mapping"
        },
        "t_mapping<t_struct<AccessControlUpgradeSafe.RoleData>>": {
          "id": "t_mapping<t_struct<AccessControlUpgradeSafe.RoleData>>",
          "valueType": "t_struct<AccessControlUpgradeSafe.RoleData>",
          "label": "mapping(key => AccessControlUpgradeSafe.RoleData)",
          "kind": "mapping"
        },
        "t_array:49<t_uint256>": {
          "id": "t_array:49<t_uint256>",
          "valueType": "t_uint256",
          "length": "49",
          "kind": "array",
          "label": "uint256[49]"
        },
        "t_string": {
          "id": "t_string",
          "kind": "elementary",
          "label": "string"
        },
        "t_uint8": {
          "id": "t_uint8",
          "kind": "elementary",
          "label": "uint8"
        },
        "t_array:44<t_uint256>": {
          "id": "t_array:44<t_uint256>",
          "valueType": "t_uint256",
          "length": "44",
          "kind": "array",
          "label": "uint256[44]"
        }
      },
      "storage": [
        {
          "contract": "Initializable",
          "path": "@openzeppelin\\contracts-ethereum-package\\contracts\\Initializable.sol",
          "label": "initialized",
          "astId": 95,
          "type": "t_bool",
          "src": "757:24:2"
        },
        {
          "contract": "Initializable",
          "path": "@openzeppelin\\contracts-ethereum-package\\contracts\\Initializable.sol",
          "label": "initializing",
          "astId": 98,
          "type": "t_bool",
          "src": "876:25:2"
        },
        {
          "contract": "Initializable",
          "path": "@openzeppelin\\contracts-ethereum-package\\contracts\\Initializable.sol",
          "label": "______gap",
          "astId": 163,
          "type": "t_array:50<t_uint256>",
          "src": "1982:29:2"
        },
        {
          "contract": "ContextUpgradeSafe",
          "path": "@openzeppelin\\contracts-ethereum-package\\contracts\\GSN\\Context.sol",
          "label": "__gap",
          "astId": 88,
          "type": "t_array:50<t_uint256>",
          "src": "1277:25:1"
        },
        {
          "contract": "AccessControlUpgradeSafe",
          "path": "@openzeppelin\\contracts-ethereum-package\\contracts\\access\\AccessControl.sol",
          "label": "_roles",
          "astId": 208,
          "type": "t_mapping<t_struct<AccessControlUpgradeSafe.RoleData>>",
          "src": "1727:44:3"
        },
        {
          "contract": "AccessControlUpgradeSafe",
          "path": "@openzeppelin\\contracts-ethereum-package\\contracts\\access\\AccessControl.sol",
          "label": "__gap",
          "astId": 453,
          "type": "t_array:49<t_uint256>",
          "src": "6927:25:3"
        },
        {
          "contract": "ERC20UpgradeSafe",
          "path": "@openzeppelin\\contracts-ethereum-package\\contracts\\token\\ERC20\\ERC20.sol",
          "label": "_balances",
          "astId": 993,
          "type": "t_mapping<t_uint256>",
          "src": "1481:46:7"
        },
        {
          "contract": "ERC20UpgradeSafe",
          "path": "@openzeppelin\\contracts-ethereum-package\\contracts\\token\\ERC20\\ERC20.sol",
          "label": "_allowances",
          "astId": 999,
          "type": "t_mapping<t_uint256>",
          "src": "1534:69:7"
        },
        {
          "contract": "ERC20UpgradeSafe",
          "path": "@openzeppelin\\contracts-ethereum-package\\contracts\\token\\ERC20\\ERC20.sol",
          "label": "_totalSupply",
          "astId": 1001,
          "type": "t_uint256",
          "src": "1610:28:7"
        },
        {
          "contract": "ERC20UpgradeSafe",
          "path": "@openzeppelin\\contracts-ethereum-package\\contracts\\token\\ERC20\\ERC20.sol",
          "label": "_name",
          "astId": 1003,
          "type": "t_string",
          "src": "1645:20:7"
        },
        {
          "contract": "ERC20UpgradeSafe",
          "path": "@openzeppelin\\contracts-ethereum-package\\contracts\\token\\ERC20\\ERC20.sol",
          "label": "_symbol",
          "astId": 1005,
          "type": "t_string",
          "src": "1671:22:7"
        },
        {
          "contract": "ERC20UpgradeSafe",
          "path": "@openzeppelin\\contracts-ethereum-package\\contracts\\token\\ERC20\\ERC20.sol",
          "label": "_decimals",
          "astId": 1007,
          "type": "t_uint8",
          "src": "1699:23:7"
        },
        {
          "contract": "ERC20UpgradeSafe",
          "path": "@openzeppelin\\contracts-ethereum-package\\contracts\\token\\ERC20\\ERC20.sol",
          "label": "__gap",
          "astId": 1502,
          "type": "t_array:44<t_uint256>",
          "src": "11045:25:7"
        },
        {
          "contract": "ERC20BurnableUpgradeSafe",
          "path": "@openzeppelin\\contracts-ethereum-package\\contracts\\token\\ERC20\\ERC20Burnable.sol",
          "label": "__gap",
          "astId": 1583,
          "type": "t_array:50<t_uint256>",
          "src": "1443:25:8"
        },
        {
          "contract": "PausableUpgradeSafe",
          "path": "@openzeppelin\\contracts-ethereum-package\\contracts\\utils\\Pausable.sol",
          "label": "_paused",
          "astId": 2207,
          "type": "t_bool",
          "src": "825:20:13"
        },
        {
          "contract": "PausableUpgradeSafe",
          "path": "@openzeppelin\\contracts-ethereum-package\\contracts\\utils\\Pausable.sol",
          "label": "__gap",
          "astId": 2296,
          "type": "t_array:49<t_uint256>",
          "src": "2073:25:13"
        },
        {
          "contract": "ERC20PausableUpgradeSafe",
          "path": "@openzeppelin\\contracts-ethereum-package\\contracts\\token\\ERC20\\ERC20Pausable.sol",
          "label": "__gap",
          "astId": 1648,
          "type": "t_array:50<t_uint256>",
          "src": "1130:25:9"
        },
        {
          "contract": "ERC20PresetMinterPauserUpgradeSafe",
          "path": "@openzeppelin\\contracts-ethereum-package\\contracts\\presets\\ERC20PresetMinterPauser.sol",
          "label": "__gap",
          "astId": 968,
          "type": "t_array:50<t_uint256>",
          "src": "3454:25:6"
        },
        {
          "contract": "CrToken",
          "path": "..\\..\\D\\Source\\CR\\contracts\\CrToken.sol",
          "label": "_totalSupply",
          "astId": 10,
          "type": "t_uint256",
          "src": "368:28:0"
        }
      ],
      "warnings": {
        "hasConstructor": false,
        "hasSelfDestruct": false,
        "hasDelegateCall": false,
        "hasInitialValuesInDeclarations": false,
        "uninitializedBaseContracts": []
      }
    }
  },
  "solidityLibs": {},
  "proxies": {},
  "manifestVersion": "2.2",
  "version": "1.0.0"
}

my code is:


pragma solidity ^0.6.0;


import '@openzeppelin/contracts-ethereum-package/contracts/Initializable.sol';
import '@openzeppelin/contracts-ethereum-package/contracts/presets/ERC20PresetMinterPauser.sol';
import '@openzeppelin/contracts-ethereum-package/contracts/access/Ownable.sol';
contract CrToken is Initializable, ERC20PresetMinterPauserUpgradeSafe   {

 uint256 private _totalSupply;


  function initialize() public initializer {
    ERC20PresetMinterPauserUpgradeSafe.initialize("Cryptomind", "CR");
      _setupDecimals(8);
	   _totalSupply = totalSupply();
	 
	   _mint(msg.sender, 2000000000 * (10 ** 8));
	  
  }


}
1 Like

Hi @Mehran_Hafizi,

When we deploy an upgradeable contract three transactions occur:

  1. Deploy implementation contract.
  2. Deploy ProxyAdmin (which controls upgrades).
  3. Deploy the proxy and initialize.

In your case it looks like only the first transaction occurred before you ran out of funds.
So transactions two and three still remain.

As the logic contract has already been deployed (the equivalent of an oz add and oz push), and the address stored in mainnet.json, you should be able to rerun oz deploy. The CLI should detect that the logic contract is already deployed and won’t deploy it again.

The deploy would still involve deploying two transactions, one for the ProxyAdmin and a second for the proxy contract pointing to the logic contract along with calling the initialization logic.

There is network congestion and gas is now at 400 Gwei https://www.ethgasstation.info/
You may want to hold off until network congestion has eased and the gas price is lower.

Hi

I will really be happy if I can deploy two other contracts,
As I remember I delete build folder but I have a backup for my CRToken.json that is the main contract, But other files in build folder are deleted

Now, Can I run oz deploy and it deploys just 2 others?

Thanks

1 Like

Hi @Mehran_Hafizi,

The ProxyAdmin and the proxy contract artifacts are used from the installed package rather than your build directory so this should be fine.

Some things to note about your contractL
The state variable _totalSupply currently doesn’t do anything.
Ownable is an unused import.

I know, I forgot remove that,
And I deployed it, Is it important to remove it now?

Thanks

1 Like

Hi @Mehran_Hafizi,

The unused import shouldn’t be an issue as this shouldn’t be included in the bytecode as it isn’t used.
The unused state variable you may need to explain to your users why it is there.

It is up to you whether you do a new deploy but gas prices are currently 400 Gwei.

Hi @abcoathup

I run oz deploy again and this time the Proxy Admin Contract deployed after 10 hours,
You can see the contract deployment here
But there isn’t any transaction for creation Token,

Cause this deployment took over of 750 seconds mainnet.json didn’t upgrade,

Now how can I initialize my contract to create tokens?

Thanks

1 Like

Hi @Mehran_Hafizi,

I can see your token now, so I assume that you reran oz deploy and initialized the state.

Yes it was done friend

Now,I want to verify my contract,I run oz verify but I got error

oz verify
? Pick a network mainnet
? Was your contract compiled with optimizations enabled? No
? Choose a remote endpoint etherscan
? Enter your Etherscan API key (get one at https://etherscan.io/myapikey) XXXXXXXX
? Pick a contract to verify CrToken
× Verifying and publishing contract source code of CrToken on etherscan (this usually takes under 30 seconds)
Error while trying to verify contract: Fail - Unable to verify

1 Like

Hi @Mehran_Hafizi,

Can you post your contract again and I can verify on Etherscan for you.

Hi @abcoathup
Of course my dear friend

pragma solidity ^0.6.0;


import '@openzeppelin/contracts-ethereum-package/contracts/Initializable.sol';
import '@openzeppelin/contracts-ethereum-package/contracts/presets/ERC20PresetMinterPauser.sol';
import '@openzeppelin/contracts-ethereum-package/contracts/access/Ownable.sol';
contract CrToken is Initializable, ERC20PresetMinterPauserUpgradeSafe   {

 uint256 private _totalSupply;


  function initialize() public initializer {
    ERC20PresetMinterPauserUpgradeSafe.initialize("Cryptomind", "CR");
      _setupDecimals(8);
	   _totalSupply = totalSupply();
	 
	   _mint(msg.sender, 2000000000 * (10 ** 8));
	  
  }


}
1 Like

Hi @Mehran_Hafizi,

I verified your token.

Hi @abcoathup
Really thanks Andrew

Every thing is fine now, And we start to transfer our token

1 Like