Skip to main content

Gas fees on Linea

If you're familiar with gas fees on Ethereum, then you know that they heavily fluctuate depending on how busy the network is (for a refresher on gas click here). Linea's gas fees depend on Ethereum's fee, and we will explain how the L2 fees are calculated, but the TLDR is that Linea's gas fees should be around 1/15th of Ethereum's, and we hope to reduce them even further in the future.

How do I check the gas price on Linea?​

If you want to check the gas price on Linea, run the code below.

curl https://linea-mainnet.infura.io/v3/your-infura-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_gasPrice","params": [],"id":1}'
note

The output of the request returns a hexadecimal equivalent of an integer representing the current gas price in wei. Convert the hexadecimal value into decimals to get the wei value. You can use any hexadecimal to decimal converter such as RapidTables.

For more information on this method, take a look at eth_gasPrice JSON_RPC.

You can also use the eth_gasprice method on Ethereum and then compare the two values to see if L2 gas price = ~L1/15 gas price.

curl https://mainnet.infura.io/v3/your-infura-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_gasPrice","params": [],"id":1}'

The Formula​

Total L2 Fee Equation

total_L2_fee=L2_base_fee+L2_miner_tip\text{total\_L2\_fee} = \text{L2\_base\_fee} + \text{L2\_miner\_tip}

The L2 fee equation is comprised of two parts, the base fee and the miner tip. The base fee is 7 wei, which is the minimum base fee a standard protocol allows. The miner tip equation is a bit complex and will be explained in more detail below.

L2 Miner Tip Equation

l2_miner_tip=(βˆ‘i(baseFee[i]Γ—0.066+reward[i]Γ—0.066)Γ—ratio[i])Γ·(βˆ‘iratio[i])l2\_miner\_tip = \left( \sum_{i} (baseFee[i] \times 0.066 + reward[i] \times 0.066) \times ratio[i] \right) \div \left( \sum_{i} ratio[i] \right)

Looking at this equation might seem overwhelming, but we are just calculating the weighted average to get the L2 miner tip.

In this equation, the following variables are constants that could change in the future as we fine-tune our gas fee calculation: base_fee_coefficient = 0.066, priority_fee_coefficient = 0.066, batchSubmissionPercentile = 15, and numBlocks = 200.

We use the eth_feeHistory JSON-RPC method with the constant parameters given above to figure out what the 'baseFeePerGas', 'gasUsedRatio', and 'reward'is on Ethereum and then find the weighted average by plugging them into the equation.

The request would look like the code below.

curl https://mainnet.infura.io/v3/YOUR-API-KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{"id": 1, "jsonrpc": "2.0", "method": "eth_feeHistory", "params": ["200", "latest", [15]] }'

Example Calculation​

For practical purposes let's assume we ran the eth_feeHistory and used numBlocks=3, and got the following response:

{"jsonrpc":"2.0","id":1,"result":{"baseFeePerGas":["1001","1002","1003","1004"],"gasUsedRatio":[0.4,0.5,0.6],"oldestBlock":"0x113159b","reward":[["901"],["902"],["903"]]}}

This maps to the following inputs for the equation:

baseFee = ["1001","1002","1003"]
reward= ["901", "902", "903"]
ratio = [0.4, 0.5, 0.6]

Using the formula, we would iterate through all the values in the list, where i ranges from 1 to 3, to obtain:

l2_miner_tip=(1001Γ—0.66+901Γ—0.66)Γ—0.4+(1002Γ—0.66+902Γ—0.66)Γ—0.5+(1003Γ—0.66+903Γ—0.66)Γ—0.60.4+0.5+0.6l2\_miner\_tip = \frac{{(1001 \times 0.66 + 901 \times 0.66) \times 0.4 + (1002 \times 0.66 + 902 \times 0.66) \times 0.5 + (1003 \times 0.66 + 903 \times 0.66) \times 0.6}}{{0.4 + 0.5 + 0.6}}

After meticulously going through all this math, you should arrive at your gas price (if you do this for 200 blocks instead of 3). This should be close to the gas price the eth_gasPrice method returns from above.