11---
2- Title : Estimate gas costs
2+ title : Estimate gas costs
33description : How to estimate gas costs on Linea
44sidebar_position : 6
55image : /img/socialCards/how-to-estimate-linea-gas-costs.jpg
66---
77
88import Tabs from ' @theme/Tabs' ; import TabItem from ' @theme/TabItem' ;
99
10- ` linea_estimateGas ` is the recommended method for estimating gas on Linea. See our [ reference page] ( ../../api/reference/linea-estimategas.mdx ) for more information.
10+ :::tip
11+ Linea supports the [ Ethereum EIP-1559 gas price model] ( https://ethereum.org/developers/docs/gas ) :
12+ ```
13+ total fee = units of gas used * (base fee + priority fee)
14+ ```
15+ and includes support for type 0, type 1 and type 2 transactions.
16+ :::
17+
18+ ` linea_estimateGas ` is the recommended method for estimating gas on Linea. See our [ reference page] ( ../../api/reference/linea-estimategas.mdx ) for more information, or our [ technology section] ( ../../technology/gas.mdx ) for more information about how gas works on Linea.
1119
1220Linea also supports:
1321- [ ` eth_estimateGas ` ] ( https://docs.infura.io/api/networks/linea/json-rpc-methods/eth_estimategas )
@@ -17,7 +25,7 @@ Linea also supports:
1725
1826## [ ` linea_estimateGas ` ] ( ../../api/reference/linea-estimategas.mdx )
1927
20- ' linea_estimateGas' returns ` gasLimit ` ,
28+ ` linea_estimateGas ` returns ` gasLimit ` ,
2129` baseFeePerGas ` , and ` priorityFeePerGas ` , and therefore provides a more precise gas estimate than
2230the alternatives.
2331
@@ -48,158 +56,4 @@ curl https://linea-mainnet.infura.io/v3/YOUR-API-KEY \
4856}
4957```
5058
51- See the [ reference page] ( ../../api/reference/linea-estimategas.mdx ) for full usage.
52-
53- ## How ` linea_estimateGas ` calculates the gas price
54-
55- The gas price returned by ` linea_estimateGas ` is based on the variable data cost of the previous
56- block with a multiplier applied as a buffer to ensure inclusion.
57-
58- Each Linea block's ` extraData ` field is populated with the following gas price values that are used
59- by ` linea_estimateGas ` to calculate the cost of a transaction:
60- - A ` FIXED_COST ` of 0.03 Gwei, which reflects infrastructure costs;
61- - ` ADJUSTED_VARIABLE_COST ` , which is the cost per byte of data submitted to L1, and;
62- - ` ETH_GAS_PRICE ` , used to set a more accurate return value for any ` eth_gasPrice ` calls.
63-
64- :::note
65-
66- The ` extraData ` field is a 32-byte space used to store arbitrary data, such as metadata or
67- additional information relevant to the block.
68-
69- On Linea, it's used by the sequencer and Linea Besu nodes running the correct plugins to expose
70- ` linea_estimateGas ` .
71-
72- :::
73-
74- Variable cost is calculated with the following formula:
75-
76- ``` bash
77- ADJUSTED_VARIABLE_COST = max(base_variable_cost, previous_variable_cost * ( 1 + delta / CHANGE_DENOMINATOR )
78- ` ` `
79-
80- Where:
81- - ` base_variable_cost` is calculated with the below formula:
82- ` ` ` python
83- variable_cost (4 bytes) = min(max(
84- (
85- (
86- (( averageWeightedBaseFee + averageWeightedPriorityFee) *
87- blob-submission-expected-execution-gas + averageWeightedBlobBaseFee * expected-blob-gas
88- ) / bytes-per-data-submission) * profit-margin
89- )
90- , min-bound), max-bound)
91- ```
92- The `profit-margin` ensures the network is sustainable. `min-bound` and `max-bound` are variable,
93- and guarantee the gas price stays within a reasonable range.
94- - `previous_variable_cost` is the value of the last `ADJUSTED_VARIABLE_COST` calculation
95- - `delta` is a decimal number that fluctuates between `- 1 .0 ` and `1 .0 ` and is calculated as:
96- ```bash
97- delta = (sum(block_calldata_size over BLOCK_COUNT) - calldata_target) / calldata_target
98- ```
99- Where:
100- - `BLOCK_COUNT` is a constant at `5 `
101- - `block_calldata_size` is the total calldata size of the target block
102- - `calldata_target` = `109 ,000 * BLOCK_COUNT / 2 ` (given that 109 ,000 is the maximum calldata
103- size allowed in each L2 block)
104- - `CHANGE_DENOMINATOR` is a constant, currently set to `32 `, designed to control the rate of change
105- of `ADJUSTED_VARIABLE_COST`
106-
107- ### Base variable cost
108-
109- The variable cost formula enables `linea_estimateGas` to price according to the variable costs of
110- submitting blob data to L1 , working out the per-byte cost of that data. The amount of the blob data
111- in each block stays roughly consistent, though the amount _per transaction_ varies, so the
112- `linea_estimateGas` API accounts for this, and ensures a gas price is returned for the transaction
113- that reflects the amount of data it contains. In turn, it ensures that the network is sustainable,
114- and that the cost to the protocol of L1 data availability is covered.
115-
116- ### Adjusted variable cost
117-
118- The overarching adjusted variable cost formula enables the gas price for the end user to
119- automatically adjust to prevent denial-of-service (DoS) attacks where a malicious actor could submit
120- a large volume of low-compute, high-data transactions at minimal cost. In theory, such a scenario
121- could prevent good-faith users from submitting transactions because all of the block's space for
122- data would be taken up by the malicious actor's transactions.
123-
124- If the calldata space of successive blocks was fully occupied, `ADJUSTED_VARIABLE_COST` would
125- increase exponentially: `1 + 1 / 32 ` (i.e. `1 + delta / CHANGE_DENOMINATOR`) would cause the
126- variable cost to double every 22 blocks (44 seconds) — 10 ,000 x over 10 minutes. The gas cost for the
127- attacker — who needs to fund many transactions — would quickly snowball to a prohibitively high
128- number, while remaining acceptable for regular users who only need to submit a handful of
129- transactions.
130-
131- This effect also works in the reverse: when calldata space usage falls, the variable cost will
132- exponentially decrease and eventually revert to `base_variable_cost`, depending on calldata usage.
133-
134- ### Variable cost and `linea_estimateGas`
135-
136- To determine the priority fee per gas, `linea_estimateGas` takes the previous block's `VARIABLE_COST`
137- into account:
138- ```python
139- min-gas-price = previousBlock.extraData.variable_cost
140- baseFeePerGas = vanillaProtocolBaseFee
141- priorityFeePerGas = MINIMUM_MARGIN * (min-gas-price * L2 _compressed_tx_size_in_bytes / L2 _tx_gas_used + extraData.fixed_cost)
142- ```
143-
144- Where:
145- - `extraData.variable_cost` is where the previous block's `VARIABLE_COST` is stored
146- block
147- - `MINIMUM_MARGIN` varies depending on the stage of the transaction:
148- - RPC method, i.e. calling `linea_estimateGas`: `1 .2 `
149- - In the transaction pool: `0 .8 `
150- - At transaction selection stage: `1 .0 `
151-
152- :::note
153- The RPC method and transaction pool values are configurable by RPC providers or those running their
154- own nodes according to preference; the transaction selection stage value is fixed. For example,
155- it may be preferable to set a lower margin to facilitate lower gas prices, but this risks
156- transactions not being included.
157- :::
158-
159- `linea_estimateGas` simulates the transaction ordering logic that the sequencer uses when building
160- blocks, and then obtains a gas price that will ensure that the priority fee is high enough for
161- inclusion. The sequencer's transaction ordering policy includes transactions in block in order of
162- highest priority fee, a system known as a priority gas auction. It also checks that the priority
163- fees offered by each transaction are high enough to support network sustainability, and cover L1
164- data costs.
165-
166- In some cases, transactions with lower priority fees are included ahead of others with higher
167- priority fees. This is because the nonce order of transactions submitted from the same account
168- takes precedence.
169-
170-
171- ## More information
172-
173- ### How gas works on Linea
174-
175- Linea supports the [Ethereum EIP-1559 gas price model](https://ethereum.org/developers/docs/gas):
176- ```
177- total fee = units of gas used * (base fee + priority fee)
178- ```
179- and includes support for type 0 , type 1 and type 2 transactions.
180-
181- Linea is EVM-equivalent, and gas therefore works extremely similarly to Ethereum. The main difference
182- is that **the base fee effectively stabilizes at 7 wei.** Linea blocks use up to around 50 % of the
183- maximum block size of 2 billion gas, and the base fee decreases or increases by 12 .5 % per block
184- according to network traffic, identically to Ethereum. However, when the base fee reaches 7 wei,
185- 12 .5 % is less than 1 wei, and the reduction is rounded down to zero; so the fee remains 7 wei.
186- The base fee is also burned, like on Ethereum.
187-
188- The gas cost to submit your transaction and include it on Ethereum involves the following fee
189- components:
190-
191- - ** Layer 2 cost**: The execution fee; the cost of including your transaction on the Linea
192- sequencer, and calculated using a similar formula to Ethereum (as described above).
193- - ** Layer 1 cost**: The cost of publishing your L2 transaction on Ethereum, which varies
194- based on the blob fee market.
195-
196- These two resource costs are abstracted by the rollup and covered by the recommended L2 gas price
197- and gas used.
198-
199- > Learn more about gas on Linea on our [support page](https:// support.linea.build/ getting- started/ what- does- gas- pay- for)
200- and release notes for [Alpha v2 ](../../release-notes.mdx#alpha-v2 ) and [Alpha v3 ](../../release-notes.mdx#alpha-v30 ).
201-
202- Linea also supports:
203- - [`eth_estimateGas`](https:// docs.infura.io/ api/ networks/ linea/ json- rpc- methods/ eth_estimategas)
204- - [`eth_gasPrice`](https:// docs.infura.io/ api/ networks/ linea/ json- rpc- methods/ eth_gasprice)
205- - [`eth_feeHistory`](https:// docs.infura.io/ api/ networks/ linea/ json- rpc- methods/ eth_feehistory).
59+ See the [ reference page] ( ../../api/reference/linea-estimategas.mdx ) for full usage.
0 commit comments