Configure free gas networks
Transactions use computational resources so have an associated cost. Gas is the cost unit and the gas price is the price per gas unit. The transaction cost is the gas used * gas price.
In public networks, the account submitting the transaction pays the transaction cost, in Ether. The miner (or validator in PoA networks) that includes the transaction in a block receives transaction cost.
In many private networks, network participants run the validators and do not require gas as an incentive. Networks that don't require gas as an incentive usually configure the gas price to be zero (that is, free gas). Some private networks might allocate Ether and use a non-zero gas price to limit resource use.
We use the term free gas network to refer to a network with a gas price of zero. A network with a gas price of zero is also known as a zero gas network or no gas network.
Some pre-crafted transactions require the deployment account to have gas available. For example, the transaction that creates the smart contract in EIP-1820.
In a free gas network, transactions still use gas but the gas price is zero, meaning the transaction cost is zero. Transaction cost = gas used * 0 (the gas price).
Configure free gas in Besu
When gas is free, limiting block and contract sizes is less important. In free gas networks, we increase the block size limit and set the contract size limit to the maximum value.
1. Set the block size
If you want to remove gas from consideration and don't mind blocks potentially taking longer to create, in the genesis file set the block size limit (measured in gas) to the maximum accepted by Hardhat (
0x1fffffffffffff). In the genesis file, specify
gasLimit following the
If you are more concerned about blocks arriving on time and don't have expensive individual transactions, set
gasLimit to a value closer to the amount of gas your validators can process in the configured block time.
2. Set the contract size
config section of the genesis file, set the contract size limit to the maximum supported size (in bytes).
3. Start Besu with a minimum gas price of zero
When starting nodes, set the minimum gas price to zero.
- Command Line
- Configuration File
4. Enable zero base fee if using London fork or later
If your network is configured to use the
londonBlock or a later hard fork, then you must also enable the
zeroBaseFee configuration. You must set this on all your nodes. Once it is set, future blocks produced by that node will set a
baseFee of 0. This is required because the London hard fork (EIP-1559) introduced a non-zero
baseFee into the block which normally means transactions require gas.
Configure free gas in Hardhat
If using Hardhat to develop on your free gas network, you also need to configure free gas in Hardhat.
Like setting block and contract size limits to their maximum values for Besu, set the transaction gas limit in Hardhat to the maximum possible.
Besu does not support private key management. To use Besu with Hardhat, you must configure a Hardhat wallet.
Set the gas price to zero.
Set the gas limit for a transaction (that is, contract creation) to be the block gas limit - 1.