Ethereum Gas Fee?
Ethereum changed how it calculates and handles ๐ ๐๐ฌ ๐๐๐๐ฌ with ๐๐๐-๐๐๐๐. It makes understanding (and explaining) how gas works on Ethereum even more complex
But you should understand it. So here we go…
First, letโs understand how gas USED to work. To understand gas, you needed to know three things:
1) ๐๐๐ฌ ๐๐จ๐ฌ๐ญ โ the amount of computation and storage used by a transaction, measured in units of โgasโ Think of this as the number of gallons of gas you need to fuel your car for a road trip…except in our case, this is the gas required to fuel the Ethereum transaction ๐
2) ๐๐๐ฌ ๐ฉ๐ซ๐ข๐๐ โ the cost per unit of gas that the sender is willing to pay Think of this as the price per gallon of gas you are willing to pay
๐๐จ๐ญ๐: Gas prices are denoted in ๐ ๐ฐ๐๐ข, which is equal to 0.000000001 ETH (10^9 ETH) Instead of saying that your gas costs 0.000000001 ether, you can say your gas costs 1 gwei
3) ๐๐๐ฌ ๐ฅ๐ข๐ฆ๐ข๐ญ โ the max amount of gas a sender is willing to use for that transaction (i.e. upper bound for gas cost) Think of this as the maximum number of gallons of gas you are willing to buy to justify the road trip. If it goes over, you cancel the road trip…
Or in the case of Ethereum, the transaction is reverted.
Therefore, your โ๐๐ซ๐๐ง๐ฌ๐๐๐ญ๐ข๐จ๐ง ๐๐๐โ was calculated as:
๐๐๐ฌ ๐๐จ๐ฌ๐ญ ๐ฑ ๐๐๐ฌ ๐ฉ๐ซ๐ข๐๐
Let’s say Alice wants to pay Bob 3 ETH. A simple ETH transfer costs 21,000 units of gas. Let’s assume the current gas price is 300 gwei (gas price changes based on the demand on the network)
Transaction fee = 21,000 gas x 300 gwei = 6,300,000 gwei or 0.0063 ETH
This entire transaction fee would go to miners for including your transaction in a block.
But ever since the London hard fork and implementation of EIP-1559 in early August 2021, there is a ๐ง๐๐ฐ ๐ฆ๐๐ญ๐ก๐จ๐ for calculating transaction fees Transactions moved from a blind auction system to a hybrid system with โbase feesโ and โtipsโ
Instead of keeping track of the ๐ ๐๐ฌ ๐ฉ๐ซ๐ข๐๐, we now have to keep track of 3 different variables:
๐๐๐ฌ๐ ๐ ๐๐ โ as the name sounds, this is the base fee per unit of gas that is used in that transaction This fee is determined by the Ethereum network itself This โfeeโ is subsequently ๐๐ฎ๐ซ๐ง๐๐
๐๐๐ฑ ๐๐ซ๐ข๐จ๐ซ๐ข๐ญ๐ฒ ๐ ๐๐ โ an optional tip that is paid directly to miners
(NOTE: The tip would be calculated as Max priority fee x Gas cost)
๐๐๐ฑ ๐ ๐๐ ๐๐๐ซ ๐๐๐ฌ โ the absolute maximum you are willing to pay per unit of gas to get your transaction included in a block (this is similar to โGas priceโ, except now it includes both the Base Fee + Max Priority fee)
๐๐๐ฌ ๐ฅ๐ข๐ฆ๐ข๐ญ stays the same, which is the max units of gas a sender is willing to use for that transaction ๐๐๐ฌ ๐๐จ๐ฌ๐ญ also stays the same, which is the amount of gas used by the transaction
Therefore.. ๐๐ซ๐๐ง๐ฌ๐๐๐ญ๐ข๐จ๐ง ๐๐๐ = (Base Fee + Max Priority fee) x Gas cost
Letโs look at a little closer at Base fee, Max priority fee, and Max fee per gas
The base fee that is set by the Ethereum network aims to have 50% full blocks. Depending on how full the last block was, the Base Fee is automatically increased or decreased
If the last block was…
๐๐% ๐๐ฎ๐ฅ๐ฅ โ Base Fee will remain unchanged
๐๐๐% ๐๐ฎ๐ฅ๐ฅ โ Base Fee will increase by the maximum 12.5% for the next block
๐% ๐๐ฎ๐ฅ๐ฅ โ Base fee will decrease by a maximum of 12.5% for the next block
๐๐๐ญ๐ฐ๐๐๐ง ๐๐% – ๐๐% ๐๐ฎ๐ฅ๐ฅ โ Base Fee will increase by less than 12.5%
๐๐๐ญ๐ฐ๐๐๐ง ๐% – ๐๐% ๐๐ฎ๐ฅ๐ฅ โ Base Fee will decrease by less than 12.5%
By automatically setting the base fee based on the current block fullness, the goal is to help prevent sudden spikes in transaction fees
Moreover, all of the transaction fees collected from base fees is ๐๐๐๐๐๐ (i.e. ETH supply is reduced)
The Max Priority Fee (i.e. โminer tipโ) is optional fee that is paid directly to miners in order to incentivize them to include your transaction in a block.
While it is optional, it is unlikely that your transaction will be included unless you set the max priority fee to some minimum
At the moment, Metamask defaults max priority fee to ๐.๐ ๐ ๐ฐ๐๐ข for a simple value transfer at “Medium” priority
If you want miners to prioritize your transactions, you probably want to increase your tip.
Now, there is one subtly to understand here:
The Max Priority Fee is the ๐ฆ๐๐ฑ๐ข๐ฆ๐ฎ๐ฆ ๐ญ๐ข๐ฉ you are willing to pay a miner
However, if the Base Fee + Max Priority Fee exceeds the Max Fee per Gas, the ๐๐๐ฑ ๐๐ซ๐ข๐จ๐ซ๐ข๐ญ๐ฒ ๐ ๐๐ ๐ฐ๐ข๐ฅ๐ฅ ๐๐ ๐ซ๐๐๐ฎ๐๐๐ so that your total fee is still below the Max fee per Gas…
This means the actual tip you end up paying to the miner might be smaller than your Max Priority Fee (e.g. if the Base Fee increases a lot by the time your transaction is included)
This is why it is currently considered best practice to set a Max Fee per gas that ๐๐ง๐ญ๐ข๐๐ข๐ฉ๐๐ญ๐๐ฌ ๐ฌ๐ฎ๐๐ก ๐๐ง ๐ข๐ง๐๐ซ๐๐๐ฌ๐ ๐ข๐ง ๐ญ๐ก๐ ๐๐๐ฌ๐ ๐ ๐๐ so that your transaction is attractive to miners even if the Base fee goes up
IF you are still paying attention, kudos to you ๐