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.

How gas works on Linea​

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 24 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.

Estimating transaction costs​

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.

Please note the linea_estimateGas endpoint is currently only available on the Linea Sepolia testnet. For more information, see our reference page.

important

Linea also supports eth_estimateGas, eth_gasPrice, and eth_feeHistory, but they usually return a higher (and less accurate) estimate than linea_estimateGas.

We recommend you use linea_estimateGas where possible to maximize the accuracy of the gas estimate.

The following example executes linea_estimateGas on the Linea testnet 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.sepolia.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.