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.
linea_estimateGas
is the recommended method for estimating gas on Linea. See our
reference page for more information.
Linea also supports:
Gas pricing​
The gas price you retrieve using methods such as linea_estimateGas
is based on values calculated
by the coordinator, and uses the gas price of
the previous block with a profitability multiplier applied.
Firstly, the coordinator records:
- A fixed cost of 0.03 Gwei, which reflects infrastructure costs, and;
- Variable cost, which is the cost per byte of data submitted to L1.
These values are sent to the sequencer so that it can compute the gas prices for the upcoming block and ensure that included transactions are profitable.
Variable cost is calculated with the following formula:
VARIABLE_COST (4 bytes) = min(max(
(
(
((averageWeightedBaseFee + averageWeigthedPriorityFee) *
blob-submission-expected-execution-gas + averageWeightedBlobBaseFee * expected-blob-gas
) / bytes-per-data-submission) * profit-margin
)
, min-bound), max-bound)
The profit-margin
is 5
, ensuring sustainable network profitability. min-bound
is 0.050000000
Gwei, and max-bound
is 0.127500000
Gwei, and together guarantee the gas price stays within a
reasonable range.
The variable cost formula is similar to the standard Ethereum gas price formula that Linea uses,
except that it allows linea_estimateGas
to price according to the variable costs of submitting
blob data to L1. The amount of the blob data in each block stays roughly consistent, though the
amount per transaction varies, so the linea_estimateGas
API accounts for this, and ensures a
gas price is returned for the transaction that reflects the amount of data it contains.
To determine the priority fee per gas, linea_estimateGas
takes the previous block's VARIABLE_COST
into account:
min-gas-price = previousBlock.extraData.variable_cost
baseFeePerGas = vanillaProtocolBaseFee
priorityFeePerGas = MINIMUM_MARGIN * (min-gas-price * L2_compressed_tx_size_in_bytes / L2_tx_gas_used + extraData.fixed_cost)
Where:
extraData.variable_cost
is the way the coordinator stores theVARIABLE_COST
for the previous blockMINIMUM_MARGIN
varies depending on the stage of the transaction:- RPC method, i.e. calling
linea_estimateGas
:1.2
- In the transaction pool:
0.8
- At transaction selection stage:
1.0
- RPC method, i.e. calling
The linea_estimateGas
formula above essentially ensures that transactions are checked for
profitability for inclusion in a block. However, the nonce order of transactions submitted from the
same account takes precedence, so there may be occasions where less profitable tranasctions are
favored for inclusion.
linea_estimateGas
​
linea_estimateGas
is the recommended method for estimating gas on Linea. It returns gasLimit
,
baseFeePerGas
, and priorityFeePerGas
, and therefore provides a more precise gas estimate than
the alternatives.
It can also help prevent transactions from being rejected due to exceeding module limits.
Example​
Request​
curl https://linea-mainnet.infura.io/v3/YOUR-API-KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0","method": "linea_estimateGas","params": [{"from": "0x971e727e956690b9957be6d51Ec16E73AcAC83A7","gas":"0x21000"}],"id": 53}'
Response​
{
"jsonrpc": "2.0",
"id": 53,
"result": {
"baseFeePerGas": "0x7",
"gasLimit": "0xcf08",
"priorityFeePerGas": "0x43a82a4"
}
}
See the reference page for full usage.