Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

When deploying on main net I get "Exceeds block gas limit" #271

Closed
1 task done
xavierlepretre opened this issue Sep 21, 2016 · 37 comments
Closed
1 task done

When deploying on main net I get "Exceeds block gas limit" #271

xavierlepretre opened this issue Sep 21, 2016 · 37 comments

Comments

@xavierlepretre
Copy link

xavierlepretre commented Sep 21, 2016


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' }
@chevdor
Copy link

chevdor commented Sep 21, 2016

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

@xavierlepretre
Copy link
Author

Like so?

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

@chevdor
Copy link

chevdor commented Sep 21, 2016

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...

@zmitton
Copy link
Contributor

zmitton commented Nov 22, 2016

+1

@makoto
Copy link
Contributor

makoto commented Feb 5, 2017

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

@salekali
Copy link

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

@kingcocomango
Copy link
Contributor

kingcocomango commented May 28, 2017

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.

@lorepieri8
Copy link

For me modifying the gas in truffle.js worked.

@smatthewenglish
Copy link

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

@felixwatts
Copy link

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?

@xavierlepretre
Copy link
Author

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

@flockonus
Copy link

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

@katopz
Copy link

katopz commented Nov 1, 2017

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?

@kevinbluer
Copy link
Member

@katopz gas: 2900000 worked for me.

@robbins
Copy link

robbins commented Nov 5, 2017

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

@ledinhhuy88
Copy link

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
    }
  }
};

@robbins
Copy link

robbins commented Nov 5, 2017

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

@xavierlepretre
Copy link
Author

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.

@robbins
Copy link

robbins commented Nov 5, 2017 via email

@xavierlepretre
Copy link
Author

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

@robbins
Copy link

robbins commented Nov 6, 2017 via email

@xavierlepretre
Copy link
Author

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

@robbins
Copy link

robbins commented Nov 7, 2017 via email

@xavierlepretre
Copy link
Author

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

@zulhfreelancer
Copy link

@ledinhhuy88's solution worked for me.

@sarthak-mishra-se
Copy link

In config file, try with

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

it worked for me

@tirthb
Copy link

tirthb commented Nov 26, 2017

@flockonus solution to update testrpc worked for me.

@swapnilpuri
Copy link

@sarthakmis solution resolved my issue.

@djudjuu
Copy link

djudjuu commented Dec 2, 2017

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

@adrobson
Copy link

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

wanderingstan added a commit to wanderingstan/Origin-demo-dapp that referenced this issue Dec 14, 2017
Was getting "Exceeds block gas limit" errors locally, and this fixed it.
trufflesuite/truffle#271 (comment)
@itoonx
Copy link

itoonx commented Jan 31, 2018

Just add the value of gas to manual

@mandarvaze
Copy link

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)

@res-Q
Copy link

res-Q commented Mar 17, 2018

This worked for me

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

@liuis
Copy link

liuis commented Apr 16, 2018

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

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

wanderingstan added a commit to OriginProtocol/origin-js that referenced this issue Apr 19, 2018
Otherwise got:
```
$ truffle migrate --network ropsten
Using network 'ropsten'.

Running migration: 1_initial_migration.js
  Deploying Migrations...
Error encountered, bailing. Network state unknown. Review successful transactions manually.
exceeds block gas limit
```

Just copied value from this comment: trufflesuite/truffle#271 (comment)
@071bctajay
Copy link

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]});

@gnidan
Copy link
Contributor

gnidan commented Oct 24, 2018

This issue is old. Closing for maintenance. Thanks!

@gnidan gnidan closed this as completed Oct 24, 2018
@sugalivijaychari
Copy link

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

how to set gas limit to 1 ether

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests