Estimate transaction costs
Linea Alpha v2 launched in February 2024, reducing gas fees by ~66%. See Alpha v2 and minimizing gas fees for details.
Linea supports the Ethereum EIP-1559 gas price model. However, as a layer 2 blockchain, Linea provides a more stable and cost-effective solution for transaction fees.
There are minor differences in the way Linea handles gas calculations when compared with Ethereum:
- The base fee uses a set price of 7 wei. Blocks created by Linea use up to 30 million gas (less than 50% of the maximum Linea block size of 61 million gas), and the fee decreases by 12.5% per block, effectively keeping it at a stable 7 wei.
- Transactions won't be sequenced if the
gasPrice
ormaxPriorityFeePerGas
falls below a certain threshold. This threshold is not static; it adjusts over time and varies depending on the specifics of each transaction. Instead, transactions are added to the pending queue until the gas price on the network drops sufficiently for the transactions to be included.
The gas cost to submit your transaction and include it on Ethereum involves the following fee components:
- Layer 2 fee - The L2 fee (execution fee) is the cost to include your transaction on the Linea sequencer and is calculated using a similar formula to Ethereum.
- Layer 1 fee - The L1 fee is the cost to publish your L2 transaction onto Ethereum and can vary based on the size of the transaction calldata.
You can use the linea_estimateGas
gas API to estimate your gas costs; the result of the
call provides an estimate that includes the layer 1 and layer 2 fees.
Calculate transaction fees
linea_estimateGas
is currently being rolled out, and will temporarily provide results similar
to eth_gasPrice
.
Use the linea_estimateGas
API method to estimate the gas cost for sending a
transaction. The method returns the recommended gas limit, the base fee per gas, and the priority fee per gas.
The priorityFeePerGas
returned by linea_estimateGas
includes the cost of submitting the transaction to
Ethereum, which can vary based on the size of the calldata.
The following example executes linea_estimateGas
on the Linea Goerli testnet.
- curl
- Result
curl -X POST --data '{"jsonrpc": "2.0","method": "linea_estimateGas","params": [{"from": "0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73","value": "0x1","gasPrice":"0x100000000","gas":"0x21000"}],"id": 53}' https://rpc.goerli.linea.build
{
"jsonrpc": "2.0",
"id": 53,
"result": {
"baseFeePerGas": "0x7",
"gasLimit": "0xcf08",
"priorityFeePerGas": "0x43a82a4"
}
}
The linea_estimateGas
API calculates gas fees as follows:
baseFeePerGas
- Uses the Linea base fee which is set at 7 wei.gasLimit
- Uses the standardeth_estimateGas
API calculation.priorityFeePerGas
- Calculates the fee required to prioritize a transaction by considering factors such as the compressed transaction size, layer 1 verification costs and capacity, gas price ratio between layer 1 and layer 2, the transaction's gas usage, the minimum gas price on layer 2, and a minimum margin (for error) for gas price estimation.
The result of the request returns hexadecimal equivalent integers of gas prices in wei. Convert the hexadecimal value into decimals to get the wei value. You can use any hexadecimal to decimal converter, such as RapidTables.