Table of Contents
Gas represents a unit that measures the volume of computational work required to perform transactions or execute operations on a blockchain network.
The maximum amount of gas a user is willing to spend is the gas limit. The network sets the block gas limit, which is the maximum amount of gas allowed in one block. The gas fee is the amount of gas used multiplied by the cost per unit of gas (plus any additional priority and/or base fee according to the network). It must be paid regardless of whether a transaction succeeds or fails. Any unspent gas is refunded.
Gas fees are paid using the network's native cryptocurrency. For example, transactions on Ethereum must be paid in ether (ETH).
Gas is used to allocate network resources efficiently and ensure fair compensation for validators. It sets a computational limit on operations, preventing excessive resource usage and potential abuse, such as infinite loops in smart contracts. Gas costs help to maintain stability by making it financially unfeasible to spam the network.
Gas fees are typically determined by the total gas used (units consumed) by a transaction multiplied by the gas price (cost per unit of gas). The exact formula varies depending on the network. Here are a couple of examples.
Example: A user wants to execute a transaction on Ethereum that consumes 21,000 gas units, with the following fee structure:
Calculation:
The total gas fee for this transaction is 0.000252 ETH.
L1 data fee calculation:
The L1 data fee consists of:
Example:
Suppose the following arbitrary parameters:
1. Estimate Transaction Size:
estimatedSizeScaled = max(128 × 10^6, 10,000 + 500 × 150)
estimatedSizeScaled = max(128,000,000, 85,000)
estimatedSizeScaled = 128,000,000
2. Calculate Weighted Gas Price Multiplier:
l1FeeScaled = 2,000,000 × 20 gwei × 16 + 1,000,000 × 15 gwei
l1FeeScaled = 640,000,000 + 15,000,000 = 655,000,000 gwei
3. Calculate Final L1 Data Fee:
l1Cost = (128,000,000 × 655,000,000 gwei)/10^12
l1Cost = 83,840 gwei
Convert to ETH by dividing the gwei amount by 1,000,000,000
1 ETH = 1,000,000,000 gwei 83,840 gwei/1,000,000,000 = 0.00008384 ETH
L1 data fee = 0.00008384 ETH
Total cost would be the L1 data fee (0.00008384 ETH) + the execution fee.
Various factors can influence gas fees. A few contributors include: