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.

Ann Kilzer
  • 380
  • 1
  • 16
Russo
  • 1,784
  • 1
  • 21
  • 30

2 Answers2

9

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) => {
    /* */
});
Ismael
  • 30,570
  • 21
  • 53
  • 96
  • 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 – Russo May 01 '18 at 09: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. – Ismael May 01 '18 at 14:45
  • Thank you. I figured it out: const provider = ganache.provider(options); – Russo Sep 27 '18 at 09: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);
Ismael
  • 30,570
  • 21
  • 53
  • 96
Russo
  • 1,784
  • 1
  • 21
  • 30