7

How can I increase the gas limit in this case? The error message is "n: Exceeds block gas limit" or "base fee exceeds gas limit".

I think there is some kind of api I need to set the block gas limit here.

Are my contracts too large? Should I test each contract one by one instead? Please advise. Thank you.

1
  • exceeds block gas limit ganache Commented Sep 27, 2018 at 9:57

2 Answers 2

8

The error message

"n: Exceeds block gas limit"

means your transaction has declared a gas value greater that the maximum allowed in the network. A client will reject such transaction.

With ganache-cli you can launch with a larger amount of gas available with the -l parameter:

ganache-cli -l 8000000 

Will launch ganache with a block gas limit of 8M.


From the readme documentation it has a mode where you pass extra options in a parameter when you launch ganache. There you can set gasLimit.

const ganache = require("ganache-cli"); const options = { gasLimit: 8000000 }; const server = ganache.server(options); server.listen(port, (err, blockchain) => { /* */ }); 
3
  • Hi Ismael, how can I add this command inside my Javascript file so I can run this file during Mocha Tests with Ganache-cli ? Thanks Commented May 1, 2018 at 9:38
  • 1
    @user2965665 How do you start your ganache instance? You can pass more options in the extra parameter, you can set gasLimit from there. Commented May 1, 2018 at 14:45
  • Thank you. I figured it out: const provider = ganache.provider(options); Commented Sep 27, 2018 at 9:56
4

Thanks to Ismael's solution:

const ganache = require('ganache-cli'); const Web3 = require('web3'); const options = { gasLimit: 8000000 }; const provider = ganache.provider(options); // quote from doc "Both .provider() and .server() take a single object // which allows you to specify behavior of ganache-cli" // https://github.com/trufflesuite/ganache-cli#using-ganache-cli const web3 = new Web3(provider); 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.