Skip to main content

Estimate transaction costs

How gas works on Linea​

Linea supports the Ethereum EIP-1559 gas price model:

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

Linea fundamentally works exactly the same as Ethereum. The one difference is that the base fee is constant at 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.

The gas cost to submit your transaction and include it on Ethereum involves the following fee components:

  • Layer 2 cost: The execution fee; the cost of including your transaction on the Linea sequencer, and calculated using a similar formula to Ethereum (as described above).
  • Layer 1 cost: The cost of publishing your L2 transaction on Ethereum, which varies based on the blob fee market.

These two resource costs are abstracted by the rollup and covered by the recommended L2 gas price and gas used.

Learn more about gas on Linea.

info

A new API for estimating gas on Linea, linea_estimateGas, will be activated soon. See our reference page for more information.

If you intend to use linea_estimateGas once it is available, you want to find out more, or you have further questions, please get in touch on Discord.

Linea supports eth_estimateGas, eth_gasPrice, and eth_feeHistory.

You can use eth_gasPrice or eth_feeHistory to get the gas price, in wei, and you can use eth_estimateGas to find out how many units of gas a specific transaction will need.

note

eth_estimateGas returns a total quantity of gas estimated for the transaction, whereas linea_estimateGas will return gasLimit, baseFeePerGas, and priorityFeePerGas once available, providing a more precise estimate.

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"
}

eth_feeHistory​

Parameters​

  • blockCount: (integer) Number of blocks in the requested range. Between 1 and 1024 blocks can be requested in a single query. If blocks in the specified block range are not available, then only the fee history for available blocks is returned.
  • newestBlock: (string) Integer representing the highest number block of the requested range, or one of the string tags latest, earliest, or pending.
  • array of integers: (optional) A monotonically increasing list of percentile values to sample from each block's effective priority fees per gas in ascending order, weighted by gas used.

Returns​

  • oldestBlock: Lowest number block of the returned range expressed as a hexadecimal number.
  • baseFeePerGas: An array of block base fees per gas, including an extra block value. The extra value is the next block after the newest block in the returned range. Returns zeroes for blocks created before EIP-1559.
  • gasUsedRatio: An array of block gas used ratios. These are calculated as the ratio of gasUsed and gasLimit.
  • reward: An array of effective priority fee per gas data points from a single block. All zeroes are returned if the block is empty.

Example​

Request​

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

Response​

{
"jsonrpc":"2.0",
"id":1,
"result":{
"baseFeePerGas":[
"0x7",
"0x7"
],
"gasUsedRatio":[0.0030745737704918033],
"oldestBlock":"0x396334",
"reward":[
["0x1427509c5"]
]
}
}

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"
}