Geth – How to Increase Gas Limit in a Block

gasgas-limitgo-ethereum

When I try to execute methods from my smart-contract, I get limited by the gas limit in a block and can't do anything.
How to change the gas limit in the block?

Best Answer

While it's advised to not alter a chain's gas limit once created, it may become necessary to fiddle with the gas limit of an existing private blockchain, especially during development.

On geth, this can be done by setting the --targetgaslimit flag when starting the node. For example, you may do the following for a network with id 666 running on localhost:8545:

  geth --networkid '666' --datadir 'path/to/your/chain/db' --targetgaslimit '9000000000000' --rpc --rpccorsdomain 'localhost:8545' --mine

The above will start your node and keep pushing the gas limit towards 9000000000000 as mining continues. Over time, the gas limit would have grown so large that you'll not have the Error: exceeds block gas limit issue anymore.

Of course, closing the node and restarting repeats the process from the initial gas limit of the chain all the way towards 9000000000000 again.

Basically, using --targetgaslimit as a flag is a very convenient way to increase or decrease the gas limit of a private chain while developing.

Related Topic