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 the variable data
cost of the previous block with a profitability multiplier applied.
The first stage of returning gas price values with linea_estimateGas
is to populate values in an
object called extraData
. The two most relevant values here are:
- 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 inserted into each block's extraData
field—32 bytes available in every Ethereum
block to store any data—and then used by the sequencer and Linea Besu nodes running the correct
plugins to expose linea_estimateGas
, in both cases with the same logic.
Variable cost is calculated with the following formula:
VARIABLE_COST (4 bytes) = min(max(
(
(
((averageWeightedBaseFee + averageWeightedPriorityFee) *
blob-submission-expected-execution-gas + averageWeightedBlobBaseFee * expected-blob-gas
) / bytes-per-data-submission) * profit-margin
)
, min-bound), max-bound)
The profit-margin
is 3
, ensuring sustainable network profitability. min-bound
and max-bound
are variable, and guarantee the gas price stays within a reasonable range.
The variable cost formula enables linea_estimateGas
to price according to the variable costs of
submitting blob data to L1, working out the per-byte cost of that data. 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. In turn, it ensures that transactions are profitable.
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 where the previous block'sVARIABLE_COST
is stored 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 RPC method and transaction pool values are configurable by node runners according to preference; the transaction selection stage value is fixed. For example, it may be preferable to set a lower margin to facilitate lower gas prices, but this risks transactions not being included.
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 transactions must be
included first.
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.