Selecting the base fee
The base fee is the minimum fee that a transaction must pay to be included in a block. Transactions that specify a maximum fee per gas that is less than the current base fee cannot be included in the blockchain. The simplest way to select a base fee is to look at the latest available OP Mainnet block. Each OP Mainnet block includes the current base fee and the amount of gas used within that block. You can use this information to predict a reasonable maximum fee for your transaction. Note that, like Ethereum, the base fee is not explicitly defined within a transaction. Instead, the maximum base fee is determined as the difference between themaxFeePerGas
and the maxPriorityFeePerGas
fields of any given transaction.
1
Retrieve the latest block
Using the JSON-RPC API or your favorite Ethereum library, retrieve the latest block on OP Mainnet.
2
Retrieve the base fee and gas used
From the block, retrieve the
baseFeePerGas
and gasUsed
fields.3
Predict the next base fee
OP Mainnet adjusts the base fee based on the amount of gas used in the previous block.
If the previous block used more than 5m gas (of the 30m gas limit), then the base fee will increase by up to 10%.
If the previous block used less than 5m gas, then the base fee will decrease by up to 10%.
Refer to the OP Mainnet EIP-1559 Parameters section for more details.
4
Select a base fee per gas
Using the current base fee per gas and the amount of gas used in the previous block, you can predict the next base fee per gas.
If you are highly sensitive to the base fee, you may want to select a base fee per gas that is either 10% higher or 10% lower than the previous base fee.
However, you may run the risk that your transaction will not be included in a block quickly.
If you are less sensitive to the base fee, you may wish to simply use a large multiple of the previous base fee (e.g. 2x).
Selecting the priority fee
The priority fee is an optional tip that can be paid to the Sequencer to incentivize them to include your transaction more quickly. The priority fee is paid in addition to the base fee. The simplest way to select a priority fee is to use theeth_maxPriorityFeePerGas
JSON-RPC method to retrieve an estimate for an acceptable priority fee.
Many Ethereum libraries will provide a function to call this JSON-RPC method.
You can also use the eth_feeHistory
JSON-RPC method to retrieve historical priority fee data.
You can then use this data to predict a reasonable priority fee for your transaction.
Alternatively, you can rely on Tenderly’s tenderly_gasPrice
to get real-time gas predictions with 3 levels of likelihood for transaction inclusion.