
Visual representation of Ethereum gas fees
Higher gas limits lead to faster transaction times, but they also come with higher costs.
Lower gas limit: When we pay a low fee to the miners, they won't prioritize the transaction, so it will take some time to execute. The higher-fee transactions will be executed first.
Previously, we had a bidding system where we could set a high price to make the transaction fast. A low fee meant low priority, leading to delays in the transaction.
Optimizing gas prices can be challenging because we can't predict gas limits and how transactions are prioritized. So, Ethereum came up with a plan where Ethereum sets a base fee for transactions, making all transactions equally prioritized. To address priority and the miners' issue of earning more, it also introduced a tip system. On top of the base fee, users can add a tip to prioritize their transaction when the network is busy.
Transaction cost = base fee + tip (when required) (busy network, high tip; not busy, regular time, low tip). This system is known as EIP-1559.
How It Works
We can define a max fee in a transaction, let's assume 0.04 ETH.
Transaction inclusion: If the base fee + tip is less than or equal to the max fee, the transaction executes and gets added to the blocks. Let's assume the base fee is 0.01 ETH and the tip we set is 0.001 ETH.
For inclusion, which means adding the transaction to the block, the transaction cost is 0.01 ETH. We set the max ETH to 0.04, so the transaction is processed using the max fee set, and the tip we set is also sent to the miner.
Understanding Refunds
We set the max fee to be 0.04 ETH. The gas used is only 0.01, so the rest of the gas, which is 0.04 - 0.01 - 0.001 (tip amount) = 0.029 (refund amount), is refunded.
Right now, Ethereum is using this EIP-1559 mechanism to perform transactions. (EIP: Ethereum Improvement Proposal: 1559th proposal)
Viewing Transaction History
A common question is: When we try to view a previous transaction, do we need to pay the gas fee?
It's simple to understand that we pay gas fees to store the transaction on the blockchain, which requires a fee to save (the gas fee). But to view transaction history, we can simply go to Etherscan or other websites to find the transaction. However, to interact with the blockchain, we need gas when we're changing or adding something, which leads to the addition of new blocks in the blockchain.