What is gas fee and how to calculate it?
Gas fee is what you have to pay for processing smart contracts and writing transactions onto a blockchain. It gets complicated how much you need to pay, how you can set your budget to pay for it, and the units commonly used. This post will explain all of that.
Ethereum high gas fee
Every blockchain charges different gas fee. For Ethereum, it is the highest of all. Transaction gas fee averages $40! You can check the latest gas price which fluctuates.
New blockchains tout low gas fee as a feature. Solana costs 0.000005 SOL, which is just $0.001! So paying gas for non-Ethereum network is a negligible cost.
As for Ethereum, you need to understand better.
Tip: If possible, try to avoid Ethereum. Instead use Polygon or Solana.
What is Gwei?
Gwei is common unit used for Ethereum gas price.
Just like $1 = 100 cents, 1 ETH = 1,000,000,000 Gwei (a billion, with 9 zeros).
Gas price is usually expressed in number of Gwei eg. 188 Gwei, because that is easier to read than 0.000000188 ETH.
Then what is Wei?
But the smallest denomination of ETH is wei, where 1 ETH = 1,000,000,000,000,000,000 Wei (a quintillion, with 18 zeros)!
The ‘g’ in Gwei stands for giga, which is 9 zeros. where 1 Gwei = 1,000,000,000 Wei.
How much gas to pay?
So far, we covered how much the gas price is eg. 1 gas today cost 188 Gwei.
It is akin to petrol price eg. 1 litre of octane-95 cost $1.84 today.
But how many unit of gas do you need? It all depends on the application and the smart contract. You have to pay more gas when the computational work is more complex.
Just like your car is different from mine, and the destinations we go is also different. But the gas price is the same.
Calculating the total gas fee
Finally we are going to calculate the actual gas fee to pay. It used to be more complex, but since 2021, the formula is simplified to:
Number of gas x Gas price
Gas price = base fee + priority fee so total gas fee is:
Number of gas x (base fee + priority fee)
Base fee is what will be burned (taken out from the total ETH supply). Priority fee (aka miner tip) is what goes to the miner/validator to incentive them to prioritising your transaction.
The question now is what is the number of gas to pay for? That depends on the complexity of the transaction.
The easiest way to estimate that is to find a similar transaction from https://etherscan.io/gastracker. For example, if I want to send Tether (USDT), then I can click on the contract to see the transactions.
Look for a completed transaction with the method Transfer, and open to look at the gas fee. I happened to click this:
It will look a bit complex, so let me explain.
- Gas usage is the actual number of gas units – 41,321 Gwei was used for sending USDT
- Base fee is 162 Gwei (I omitted the decimals) which will be burned
- Gas price is 182 Gwei
- We can derive the priority fee = 182-162 = 20 Gwei
- Transaction fee is the final gas fee paid, and it all works out correctly
41,321 x 182 = 7527572.195261188 Gwei = 0.007527572195261188 ETH
Tip: Price alert
The biggest factor is the fluctuating gas price. You can set a price alert from services such as Crypto.com DeFi Wallet app.
It also usually dips over the weekends, when there is lesser transactions.
Tip: MetaMask and an example
I am going to transfer $734 of USDT on Ethereum.
When using a wallet like MetaMask, you can set the limits to how much you are willing to pay. You have to change in advanced settings to see the options.
Before you confirm a transaction, you can edit the limits.
From there, you can adjust 3 limits.
- Recommendation - switch to Low
- Gas limit is the maximum number of gas usage. Usually don’t have to change.
- Max priority fee is how much to pay to the miners. Because this is much lower than base fee, you might want to accept the recommended Low.
- Max fee is the base + priority fee aka gas price. Because this fluctuates much, you can set a much lower limit
I lowered from the recommended 146 to 115. There will be a warning, but that’s ok.
It will be slower. But it was processed in a few mere minutes. Here’s the transaction details.
My actual gas price is only 110 Gwei. Compared to a few hours ago where someone had paid 182 Gwei, I had some great savings 😆