0

I am facing issues while deploying my contract on the main net. I have tried the below contract deployment on rinkeby and ropsten without any issue. But when I am deploying this contract to the mainnet it gives me out of the gas issue. Even though I have 1 ether available in my existing ethereum deployment address. I tried numerous values in the gas and gas limit (inside migration and truffle config) but still, I am facing out of gas issues.

Error that i am facing is

"MYTToken" ran out of gas (using a value you set in your network config or deployment parameters.)

My migration script (address has been masked) is as below. I have tried migrating it without from and gaslimit. I have tried different variation of gaslimit and it didn't work. I have also checked and edited the truffle config file many times.

Truffle config file.

 mainnet: {
      provider: () => new HDWalletProvider(mnemonic_m, `wss://mainnet.infura.io/ws/v3/MYKEYS`),
      network_id: 1,       // Ropsten's id
      gas: 8500000,           // Gas sent with each transaction (default: ~6700000)
      gasLimit: 29999829,         // Ropsten has a lower block limit than mainnet
      confirmations: 8,    // # of confs to wait between deployments. (default: 0)
      timeoutBlocks: 600,  // # of blocks before a deployment times out  (minimum/default: 50)
      skipDryRun: true     // Skip dry run before migrations? (default: false for public nets 
      },

Migration file

var token = artifacts.require('MYTToken');

module.exports = async (deployer) => {

  await deployer.deploy(token,{'from':'0x****************************************','gasLimit':'300000000000'}).then(async function() {
        
        const tokenAddress =  token.address;
        
        console.log("Token Contract:"+tokenAddress);
    
        return true;
      });
    };

My contract code

pragma solidity >= 0.8.0;

import "../openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import "../openzeppelin-contracts/contracts/access/Ownable.sol";
import "../openzeppelin-contracts/contracts/utils/math/SafeMath.sol";
import "./interfaces/IMYTStakingContract.sol";

contract MYTToken is ERC20, Ownable {
  using SafeMath for uint256;

  mapping (address => bool) private isMinter;
  bool private isInitialized = false;

  IMYTStakingContract private stakingContract;
  address private stakingConAddr;


  modifier onlyMinter {
    require(isMinter[msg.sender]);
    _;
  }

  /**
  *  ERC20 name of the token
  *  ERC20 symbol (ticker) of the token
  */
  constructor()
  ERC20("MYT Token", "MYT")
  {
    isMinter[msg.sender] = true;
  }

  /**
  * Initialize the the dedicated minters and reference to the MYT staking contract 
  *
  * @param _minterAddresses: list of addresses to receive minter roles
  * @param _stakingContractAddr: address of the staking contract, needs to support IStakingContract
  */
  function init(
    address[] calldata _minterAddresses,
    address _stakingContractAddr
  )
  external
  onlyOwner
  {
    require(_stakingContractAddr != address(0), "Staking contract cannot be zero address");
    require(!isInitialized, "Minters are already set");
    require(_minterAddresses.length > 0, "Trying to initialize with no minters");
    
    for (uint8 i=0; i<_minterAddresses.length; i++) {
      require(_minterAddresses[i]  != address(0), "MYTToken: Trying to init with a zero address minter");
      isMinter[_minterAddresses[i]] = true;
    }
    stakingContract = IMYTStakingContract(_stakingContractAddr);
    isInitialized = true;
    stakingConAddr = _stakingContractAddr;
  }

  /**
  * Minting wrapper for the privileged role
  */
  function mint(address _account, uint256 _amount) public onlyMinter {
    require(_account != address(0), "MYTToken: Trying to mint to zero address");
    require(_amount > 0, "MYTToken: Trying to mint zero tokens");
    _mint(_account, _amount);
  }

  /**
  * Total supply that includes "virtual" tokens which will be minted by staking, to date
  */
  function totalSupplyVirtual() public view returns (uint256) {
    return totalSupply().add(stakingContract.totalUnmintedInterest());
  }

  function getStAddress() public view returns(address ret) {
    return stakingConAddr;
  }
}

Detail Error

Starting migrations...
======================
> Network name:    'mainnet'
> Network id:      1
> Block gas limit: 29970677 (0x1c950f5)


1_initial_migration.js
======================

   Deploying 'MYTToken'
   ---------------------

Error:  *** Deployment Failed ***

"MYTToken" ran out of gas (using a value you set in your network config or deployment parameters.)
   * Block limit:  29970677 (0x1c950f5)
   * Gas sent:     5500000 (0x53ec60)
    at C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\deployer\src\deployment.js:365:1
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at Migration._deploy (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:74:1)
    at Migration._load (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:61:1)
    at Migration.run (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:212:1)
    at Object.runMigrations (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:150:1)
    at Object.runFrom (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:110:1)
    at Object.run (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:87:1)
    at runMigrations (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:263:1)
    at Object.run (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:228:1)
    at Command.run (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\command.js:136:1)

truffle(mainnet)>

truffle(mainnet)> migrate

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.



Starting migrations...
======================
> Network name:    'mainnet'
> Network id:      1
> Block gas limit: 29999829 (0x1c9c2d5)


1_initial_migration.js
======================

   Deploying 'MYTToken'
   ---------------------
Error:  *** Deployment Failed ***

"MYTToken" ran out of gas (using a value you set in your network config or deployment parameters.)
   * Block limit:  29999829 (0x1c9c2d5)
   * Gas sent:     8500000 (0x81b320)

    at C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\deployer\src\deployment.js:365:1
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at Migration._deploy (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:74:1)
    at Migration._load (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:61:1)
    at Migration.run (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:212:1)
    at Object.runMigrations (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:150:1)
PS G:\mycompany\myt_final_coin> truffle console --network mainnet
truffle(mainnet)> migrate

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.



Starting migrations...
======================
> Network name:    'mainnet'
> Network id:      1
> Block gas limit: 29970562 (0x1c95082)


1_initial_migration.js
======================

   Deploying 'MYTToken'
   ---------------------


"MYTToken" ran out of gas (using a value you set in your network config or deployment parameters.)
   * Block limit:  29970562 (0x1c95082)
   * Gas sent:     8500000 (0x81b320)

    at C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\deployer\src\deployment.js:365:1
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at Migration._deploy (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:74:1)
    at Migration._load (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:61:1)
    at Migration.run (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:212:1)
    at Object.runMigrations (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:150:1)
    at Object.runFrom (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:110:1)
    at Object.run (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:87:1)
    at runMigrations (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:263:1)
    at Object.run (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:228:1)
    at Command.run (C:\Users\mycomp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\command.js:136:1)

truffle(mainnet)>
(To exit, press Ctrl+C again or Ctrl+D or type .exit)
truffle(mainnet)> .exit
PS G:\mycompany\myt_final_coin> truffle console --network mainnet
truffle(mainnet)> web3.eth.getBalance(accounts[0])
'265403053660175674'
truffle(mainnet)>
1
  • You might also want to check gasPrice (if you use old tx format) and/or maxFeePerGas, maxPriorityFeePerGas if you use EIP-1559 compatible tx to ensure you have enough balance in your account regarding those parameters. Apr 10, 2023 at 6:12

1 Answer 1

0

'gasLimit':'300000000000' during deployment may cause this error, because this is much higer value than your balance or even block gas limit. Insert there only that value that you can actually spend.

1
  • I actually made that after some tries even without mentioning the gas limit in the migration. I was using gas inside the config file for 5500000 but still, I am getting out of the gas issue. My understanding is gas is represented as GWei. Kindly advise Dec 20, 2021 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.