[Ethereum] Truffle deployment on test network says: Error: exceeds block gas limit

contract-deploymentcontract-developmentgasout-of-gastruffle

I'm trying to deploy a sample contract (following this guide) but I'm receiving an error of not enough gas. I changed the numbers a little but could not fix it. I saw this question in stack exchange but there are few things I don't understand in the answer suggested there:

  • What does it mean to modify the genesis block as follows?

    "You can modify your genesis block to have a gas limit of 0x2fefd8
    which is the same as the main network (3,141,592 gas). You will also need to reset that test chain since you'll be changing the genesis block."

  • In the js files I print below there are two "gas" parameters: one in 2_deploy_contracts.js and the other in truffle.js. What each of them means (how do they affect the deployment of a contract)? Are there any other places that relate to amount of gas issues?

My error and file contents:

~/voting$ truffle deploy
Using network 'development'.

Running migration: 1_initial_migration.js
  Deploying Migrations...
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: exceeds block gas limit
    at Object.InvalidResponse (/usr/lib/node_modules/truffle/build/cli.bundled.js:37022:16)
    at /usr/lib/node_modules/truffle/build/cli.bundled.js:209743:36
    at XMLHttpRequest.request.onreadystatechange (/usr/lib/node_modules/truffle/build/cli.bundled.js:208522:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/usr/lib/node_modules/truffle/build/cli.bundled.js:210395:18)
    at XMLHttpRequest._setReadyState (/usr/lib/node_modules/truffle/build/cli.bundled.js:210685:12)
    at XMLHttpRequest._onHttpResponseEnd (/usr/lib/node_modules/truffle/build/cli.bundled.js:210840:12)
    at IncomingMessage.<anonymous> (/usr/lib/node_modules/truffle/build/cli.bundled.js:210800:24)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)

migrations/1_initial_migration.js

var Migrations = artifacts.require("./Migrations.sol");
module.exports = function(deployer) {
  deployer.deploy(Migrations);
};

migrations/2_deploy_contracts.js

var Voting = artifacts.require("./Voting.sol");
module.exports = function(deployer) {
  deployer.deploy(Voting, ['Rama', 'Nick', 'Jose'], {gas: 5000000});
};

truffle.js
require('babel-register')

module.exports = {
  networks: {
    development: {
      host: 'localhost',
      port: 8545,
      network_id: '*', // Match any network id
      // gas:400000000000,
      gas:1000258612000000000,
      from: "0xf212bb926f7a831ff745e4236fc704a9947de77c"
    }
  }
}

Best Answer

Inside truffle.js, add

,gas: 4600000

Don't forget the little "," so it looks like

  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*",
      gas: 4600000
    }
Related Topic