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 Truffle (0x1fffffffffffff
). In the genesis file, specify gasLimit
following the config
key.
{
"config": {
....
},
...
"gasLimit": "0x1fffffffffffff",
....
}
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
In the config
section of the genesis file, set the contract size limit to the maximum supported size (in bytes).
(
"config": {
...
"contractSizeLimit": 2147483647,
...
}
...
}
3. Start Besu with a minimum gas price of zero
When starting nodes, set the minimum gas price to zero.
- Command Line
- Configuration File
--min-gas-price=0
min-gas-price=0
Command Line
In a free gas network, ensure the minimum gas price is set to zero for every node. Any node with a minimum gas price set higher than zero will silently drop transactions with a zero gas price. You can query a node's gas configuration using eth_gasPrice
.
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.
{
"config": {
"londonBlock": 0,
"zeroBaseFee": true,
...
},
...
}
Configure free gas in Truffle
If using Truffle to develop on your free gas network, you also need to configure free gas in Truffle.
Like setting block and contract size limits to their maximum values for Besu, set the transaction gas limit in Truffle to the maximum possible.
Besu does not support private key management. To use Besu with Truffle, you must configure a Truffle wallet.
Update truffle-config.js
Update the truffle-config.js
file:
Set the gas price to zero.
gasPrice: 0;
Set the gas limit for a transaction (that is, contract creation) to be the block gas limit - 1.
gas: "0x1ffffffffffffe";