Skip to main content

Estimate transaction costs

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. The EIP-1559 model formula is:

units of gas used * (base fee + priority fee)

Using parameters in the Linea source code, the formula can be rendered as:

gasLimit * (maxBaseFeePerGas + maxPriorityFeePerGas)

However, 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.

To read more about how gas works on Linea, see Gas on Linea.

Estimating transaction costs​

info

The best method for estimating gas on Linea, linea_estimateGas, is currently unavailable, and will be activated soon. See our reference page for more information.

Please get in touch via the Linea Discord if you intend to use linea_estimateGas once it is available.

Linea supports eth_estimateGas, eth_gasPrice, and eth_feeHistory.

We suggest you first use eth_gasPrice to get the gas price, in wei, and then use this value in eth_estimateGas.

eth_estimateGas returns a total quantity of gas estimated for the transaction, contrasting with linea_estimateGas, which also will return baseFeePerGas and priorityFeePerGas once available. eth_estimateGas is therefore less precise and generally provides a higher estimate.

Step 1: eth_gasPrice​

Parameters​

None.

Returns​

A hexadecimal equivalent of an integer representing the current gas price in wei.

Example​

Request​

curl https://rpc.sepolia.linea.build \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0","method": "eth_gasPrice","params": [],"id": 1}'

Response​

{
"jsonrpc":"2.0",
"id":1,
"result":"0x12eb10e0c"
}

Step 2: eth_estimateGas​

Parameters​

  • TRANSACTION CALL OBJECT [required]
    • from: [optional] 20 Bytes - The address the transaction is sent from.
    • to: 20 Bytes - The address the transaction is directed to.
    • gas: [optional] Hexadecimal value of the gas provided for the transaction execution. eth_estimateGas consumes zero gas, but this parameter may be needed by some executions.
    • gasPrice: [optional] Hexadecimal value of the gas price used for each paid gas.
    • maxPriorityFeePerGas: [optional] Maximum fee, in Wei, the sender is willing to pay per gas above the base fee.
    • maxFeePerGas: [optional] Maximum total fee (base fee + priority fee), in Wei, the sender is willing to pay per gas.
    • value: [optional] Hexadecimal value of the value sent with this transaction.
    • data: [optional] Hash of the method signature and encoded parameters. See the Ethereum contract ABI specification.
    • block number: [required] A string representing a block number, or one of the string tags latest, earliest, pending, safe, or finalized. See the default block parameter.

Returns​

A hexadecimal of the estimate of the gas required for the given transaction.

Example​

Request​

curl https://rpc.sepolia.linea.build \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_estimateGas","params": [{"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567","gasPrice": "0x12eb10e0c","value": "0x9184e72a"}],"id":1}'

Response​

{
"jsonrpc":"2.0",
"id":1,
"result":"0x5208"
}