When I try to execute methods from my smart-contract, I get limeted by gas limit in block and cant do anything. How to change gas limit in block?
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.
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
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
--targetgaslimit as a flag is a very convenient way to increase or decrease the gas limit of a private chain while developing.
Can't or shouldn't.
The block gaslimit is a property of the network. If you're using a private chain you can fiddle with it in the genesis block. On a real blockchain, this property is periodically voted on by the miners. See Yellow Paper.
More info here: What does each genesis.json parameter mean?
gasLimit A scalar value equal to the current chain-wide limit of Gas expenditure per block. High in our case to avoid being limited by this threshold during tests. Note: this does not indicate that we should not pay attention to the Gas consumption of our Contracts.
Consider restructuring the contract with a mind to reducing the gas requirement. The live Ethereum network has a moveable limit. https://ethstats.net/
Hope it helps.
@Daniel Okwufulueze's answer, sets the gas limit to 9000000 Million.
I do not recommend to set gat limit to exteremly high gas value. Even if you are using a private chain, its better to set
gasLimit close to the real mainnet's
gasLimit, in order to maintain a realistic simulation environment.
On Ethereum mainnet, current gas limit is ~10 Million (checked on 4 January 2020), please see https://etherscan.io/chart/gaslimit.
Please just add following flag on miner or signer nodes when starting
geth --targetgaslimit '10000000' , follows by other flags.