6

I can deploy my contract on Remix (Javascript VM and Rinkeby), but if I try to use truffle develop and migrate, I am getting an error: Error: Exceeds block gas limit. The gas used in Remix is 3585084.

How can I make it work in truffle?

4 Answers 4

5

Try manually setting the gas limit in your truffle.js file for your development network:

development : {
 ...
 gas: 4612388
}
4
  • 1
    This works, but there is still another limit that seems hardcoded around 6700000 gas.
    – rhlsthrm
    Commented Mar 5, 2018 at 16:49
  • 6
    As of Jan 2019, the hardcoded gas limit in ganache-cli is 6721975. Commented Jan 17, 2019 at 12:04
  • which truffle code /home/user/.nvm/versions/node/v8.11.1/bin/truffle crtl+f 6721975
    – Barrard
    Commented Jan 22, 2019 at 12:48
  • Works well, BUT... is user runs truffle develop, then network name must be develop (not development)
    – Vanja Dev
    Commented Jul 15, 2022 at 17:47
5

The gas parameter in truffle.js is NOT the chain's block gas limit. It means maximum to pay for deploys.

So doesn't matter how big you set the number as long as a actual gas required is larger than the hardcoded chain block gas limit you will get the same error again and again!

Here's my answer:

Truffle contract deployment either exceeds block gas limit or out of gas

Hope it helps.

2

You can check your maximum gas limit with web3.eth.getBlock("pending").gasLimit command in truffle develop console.

Example:

truffle(develop)> web3.eth.getBlock("pending").gasLimit
6721975

That is the maximum number you can set in truffle.js

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

Source: https://github.com/trufflesuite/truffle/issues/271#issuecomment-341952559

1

I solved it and now can run mocha ganache tests without truffle. Solidity Exceeds block gas limit during Mocha Tests with Ganache-cli

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.