Truffle: When deploying on main net I get "Exceeds block gas limit"

Created on 21 Sep 2016  Â·  37Comments  Â·  Source: trufflesuite/truffle

  • [x] I've asked for help in the Truffle Gitter before filing this issue.

Issue

I ran truffle migrate --network main, with my Geth running the main net. At every step, I would get:

Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: Exceeds block gas limit

Steps to Reproduce

Do truffle migrate targeting the main net.

Expected Behaviour

I would have thought that a reasonable amount of gas would be given to the transactions.

Actual Results

  • When it did deployer.deploy(Migrations); I got this block gas limit error.
  • So I changed the line to deployer.deploy(Migrations, { gas: 300000 });
  • Then when it did, behind the scenes, migrations.setCompleted(1), again I got block gas limit.
  • So I did this .setCompleted(1) by hand within Geth
  • Then when it did deployer.deploy(MyContract); I got this block gas limit error.
  • So I changed the line to deployer.deploy(MyContract, { gas: 300000 });
  • Then when it did, behind the scenes, migrations.setCompleted(2), again I got block gas limit.
  • So I did this .setCompleted(2) by hand within Geth

On my Geth console, I noticed the following:

> eth.getBlock("pending").gasLimit
4709181
// Wait for a block
> eth.getBlock("pending").gasLimit
4704588

Environment

  • Operating System: AWS AMI
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:        14.04
Codename:       trusty
  • Truffle version:
$ truffle version
Truffle v2.0.7
  • Ethereum client:
$ ~/go-ethereum/build/bin/geth version
Geth
Version: 1.4.12-stable-421df866
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.6
OS: linux
GOPATH=
GOROOT=/usr/lib/go
  • node version:
$ nodejs --version
v4.5.0
  • npm version:
$ npm version
{ npm: '2.15.9',
  ares: '1.10.1-DEV',
  http_parser: '2.7.0',
  icu: '56.1',
  modules: '46',
  node: '4.5.0',
  openssl: '1.0.2h',
  uv: '1.9.1',
  v8: '4.5.103.37',
  zlib: '1.2.8' }

Most helpful comment

Your value (500000) seems rather low. The default value is 4712388.
Try with the default or lower it to 4612388. Not sure why but it then worked on my end...

All 37 comments

In your truffle.js, can you reduce rpc.gas a tiny bit and see if that helps?

Like so?

  rpc: {
    host: "localhost",
    port: 8545
  },
  networks: {
    "main": {
      network_id: 1,
      gas: 500000
    }
  }

Your value (500000) seems rather low. The default value is 4712388.
Try with the default or lower it to 4612388. Not sure why but it then worked on my end...

+1

I get the same message even when I set gas limit to 1 ether

I'm getting the same error. Unable to migrate contracts.

I am also having this issue. Unable to deploy contracts

foo@Moko:~/Git/bar$ truffle deploy
Using network 'development'.

Running migration: 1_initial_migration.js
  Deploying Migrations...
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: Error: Exceeds block gas limit
    at StateManager.queueTransaction (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/lib/statemanager.js:291:21)
    at GethApiDouble.eth_sendTransaction (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/lib/subproviders/geth_api_double.js:232:14)
    at GethApiDouble.handleRequest (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/lib/subproviders/geth_api_double.js:61:10)
    at next (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/node_modules/web3-provider-engine/index.js:95:18)
    at SolcSubprovider.handleRequest (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/node_modules/web3-provider-engine/subproviders/solc.js:28:7)
    at next (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/node_modules/web3-provider-engine/index.js:95:18)
    at VmSubprovider.handleRequest (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/node_modules/web3-provider-engine/subproviders/vm.js:40:12)
    at next (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/node_modules/web3-provider-engine/index.js:95:18)
    at GethDefaults.handleRequest (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/lib/subproviders/gethdefaults.js:17:12)
    at next (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/node_modules/web3-provider-engine/index.js:95:18)
    at Object.InvalidResponse (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/web3/lib/web3/errors.js:35:16)
    at /home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/web3/lib/web3/requestmanager.js:86:36
    at XMLHttpRequest.request.onreadystatechange (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/web3/lib/web3/httpprovider.js:118:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:64:18)
    at XMLHttpRequest._setReadyState (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:354:12)
    at XMLHttpRequest._onHttpResponseEnd (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:509:12)
    at IncomingMessage.<anonymous> (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:469:24)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:188:7)
    at endReadableNT (_stream_readable.js:975:12)

Resolved by the solution found @ stackoverflow from user Matthew Schmidt

Possibility two: you're giving the transaction too high of a gasLimit. If the transaction has a limit of 2,000,000, it'd stop you since it could theoretically go over the block gas limit, even if in practice it won't. If this is the case, see if you can reduce the transaction's gasLimit while remaining above the amount it actually needs--that might do the trick.

For me modifying the gas in truffle.js worked.

yeeaaa @chevdor! modifying the gas in truffle.js worked for me as well :)

If I set the gas in truffle.js to 4500000 I get out of gas. If I set it to 4750000 i get exceeds block gas limit. I could continue the trial and error binary search of the gas space, but I suspect there may be no gas number that satisfies both constraints. What do I do?

As you describe it, your problem is with your contract constructor.

Also had this gas deployment issue with truffle 3.4.11. Changing the gas limit didn't help me (already had mine at 4M), but two things did the trick:

  • update testrpc to latest npm install -g ethereumjs-testrpc
  • i had a function declared but not implemented in my contract (function myfn(uint256 _count);), and apparently that was causing unreasonable gas estimates?? Removing it fixed the problem

Here's result for truffle 4.0 with testrpc, at old MetaCoin example.

4712388 = out of gas
4712389 = Exceeds block gas limit

But it working fine in truffle develop just broke external testrpc

Any idea for magic number?

@katopz gas: 2900000 worked for me.

I get this error too, none of these gas values work for me.

I had the same issue with truffle 4.0.1

this is my workaround

$ truffle console
truffle(development)> web3.eth.getBlock("pending").gasLimit
6712390

then in the truffle.js:

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      gas: 6712390,
      network_id: "*" // Match any network id
    }
  }
};

@ledinhhuy88 I followed the above steps you just posted, and I still got the same error (truffle version 4.0.1)

Some of you guys have contracts that just don't deploy. Either because you have a mammoth one that has too big a bytecode or because you throw in the constructor.
This thread is not what you are looking for.

Nope, mines issue #650 and I basically followed a tutorial, so it should
compile properly.

On Nov 5, 2017 3:57 PM, "Xavier Leprêtre" notifications@github.com wrote:

Some of you guys have contracts that just don't deploy. Either because you
have a mammoth one that has too big a bytecode or because you throw in
the constructor.
This thread is not what you are looking for.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/trufflesuite/truffle/issues/271#issuecomment-342004932,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AeABokRHqUNpsOCegfcG4Yaatox0HxhEks5sziFPgaJpZM4KC3bx
.

@NateDev100 So perhaps you can remove your comments to avoid misleading subsequent visitors.

How's it misleading? That's the error I'm getting

On Nov 6, 2017 9:19 AM, "Xavier Leprêtre" notifications@github.com wrote:

@NateDev100 https://github.com/natedev100 So perhaps you can remove your
comments to avoid misleading subsequent visitors.

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/trufflesuite/truffle/issues/271#issuecomment-342161943,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AeABooqiO2IBzO6GJ8Z4KyAdc62ealynks5szxWKgaJpZM4KC3bx
.

This issue here is specifically for main net. Not just "deployment".

Well I get the same error with main net as well so... Yeah

On Nov 6, 2017 10:54 AM, "Xavier Leprêtre" notifications@github.com wrote:

This issue here is specifically for main net. Not just "deployment".

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/trufflesuite/truffle/issues/271#issuecomment-342191901,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AeABohaNWam2tlzhkPR6mwscygZ3oTimks5szyu0gaJpZM4KC3bx
.

Of course, if you get an error on any net, it has nothing to do with the net, or the main net.

@ledinhhuy88's solution worked for me.

In config file, try with

module.exports = {
networks: {
development: {
host: 'localhost',
port: 8545,
network_id: '*',
gas:4712388
}
}
};

it worked for me

@flockonus solution to update testrpc worked for me.

@sarthakmis solution resolved my issue.

i had the same issue with either running out of gas or exceeding block gas limit (on the development-network). my contracts were big.
With truffle 4.x, the solc-optimizer got switched off by default. switching it back on solved it for me:

in truffle.js
solc: { optimizer: { enabled: true, runs: 200 } }

maybe without optimizing they exceeded the max stack-depth?...not sure, happy it works

I got an error message with gas:6700000. I changed it to 670000 and it worked.

Just add the value of gas to manual

I think the error is too generic and misleading. That is why it works for some people and does not for some others, because the root cause is different, but the error is same. (too generic)
I blogged about my experience here : https://mandarvaze.bitbucket.io/posts/please-check-your-gas-amount-maybe-misleading.html
tl;dr : It was "code" issue (Should have been compile error IMO)

This worked for me

ropsten: {
host: "127.0.0.1",
port: 8545,
network_id: 3,
gas: 4712388,
// gasPrice: xxx,
from: "0x689bb9068f12BfaCEF6aeeC6f37d9fa5963d4bd7" //
}

try
eth.getBlock("latest").gasLimit
my : 2257178

then truffle.js:
gas: 2257177,
It's worked for me

I found that my cause of the error was missing '0x' in .deploy( ) parameter
So I had to use
web3.eth.Contract(JSON.parse(filename.interface)).deploy({data:'0x' +bytecode}).send({gas:'1000000', from: accounts[0]});

This issue is old. Closing for maintenance. Thanks!

I get the same message even when I set gas limit to 1 ether

how to set gas limit to 1 ether

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ripper234 picture ripper234  Â·  4Comments

Katsu1991 picture Katsu1991  Â·  3Comments

hefgi picture hefgi  Â·  3Comments

ysfAskri picture ysfAskri  Â·  4Comments

oed picture oed  Â·  3Comments