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?
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.
I just wanted to contribute a solution to similar problems. When you get the error: "err: Error: Returned error: exceeds block gas limit" it might be triggered by the amount of gas you sent for processing the transaction. Normally, you'd think it is fine to send more gas than necessary because any unused gas would be refunded. However, if you provide too much gas to use to process your transaction, it will crash with this error. It seems that the assumption the miner makes is that if you needed to send that much gas, the underlying function is too complicated to process and error prone. They'd have better luck making money mining a simpler transaction.
According to https://www.ethgasstation.info/ The maximum block limit is 8000000, so the amount of gas for your transaction must be less than or equal to this number in hex, i.e. web3.utils.toHex('8000000'), and the same should be true for the gas required of the contract's function.