Skip to main content

Estimate transaction costs

Reducing gas fees

Building on gas optimizations introduced with Alpha v2 in February 2024, Linea implemented EIP-4844 with Alpha v3 on March 26 2024. Gas fees are anticipated to be a fraction of what they were. See here 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 or maxPriorityFeePerGas 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 blob fee market.

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​

note

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 mainnet using the public RPC URL.

tip

You can also call the API using Infura's supported Linea endpoints.

curl -X POST --data '{"jsonrpc": "2.0","method": "linea_estimateGas","params": [{"from": "0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73","gasPrice":"0x100000000","gas":"0x21000"}],"id": 53}' https://rpc.linea.build

The linea_estimateGas API calculates gas fees as follows:

  • baseFeePerGas - Uses the Linea base fee which is set at 7 wei.
  • gasLimit - Uses the standard eth_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.
note

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.