What is Gas Fee
Gas Fee was originally designed to compensate network validators for the energy costs of validating transactions, and to provide a layer of security to the blockchain network itself - making it more expensive for users to send spam transactions maliciously.
The term Gas was originally invented by Ethereum. According to the Ethereum developer page, "Gas is essential to the Ethereum network. It is the fuel that allows it to operate, in the same way, that a car needs gasoline to run."
Some of the other blockchain networks follow the Gas Fee name (e.g. Polygon, BNB Chain, etc.). Some may call these transaction fees, miner fees, or other similar fees (e.g. Bitcoin, Litecoin, etc.), but they are essentially fees paid by users to network validators in order to execute transactions.
Calculation of Gas Fees
- Gas Limit is the maximum amount of Gas Unit that a user is willing to spend on a transaction, which is a measure of the amount of computational work required to perform a particular operation on the Ethereum network. Therefore, the number of Gas Units required to execute different transactions is different. For example, a standard $ETH transfer transaction requires 21,000 units of Gas, while transactions involving smart contracts are generally more complex and require more Gas Units.
- Base Fee refers to the minimum Gas Fee required for a transaction to be executed in Ethereum, which is dynamically adjusted based on the number of users interacting with the network at any given time. Real-time Base Fee can be viewed in the Etherscan Gas Tracker.
- Priority Fee refers to an additional fee that is actively attached by the user to make a transaction executed faster. Validators of Ethereum can see which transactions have Priority Fees attached to them When a validator executes a transaction with a Priority Fee attached, he will receive those fees. So this mechanism encourages validators to prioritize transactions with a higher Priority Fee to earn more. On the other hand, users who want to complete transactions faster than other users will need to attach more Priority Fee to their transactions.
Please Note: The above calculation method is the current calculation method after the London Upgrade of Ethereum in August 2021. To understand the calculation method before the London upgrade, please refer to EIP-1559.
Refund of Gas Fee
Assuming we set the Gas Limit to 50,000 to execute an $ETH transfer transaction, the validator will consume 21,000 Units of Gas and the remaining 29,000 will be returned.
Suppose we set the Gas Limit to 20,000, the network validator will still consume 20,000 Units of Gas in an attempt to complete the transaction, but the transaction will not be confirmed because there are not enough Gas Units. However, since the validator has already completed 20,000 Gas Units worth of work, the 20,000 Units of Gas will be consumed and not returned.
When trading in Ethereum and paying Gas Fee, we often see the word “Gwei” as the unit of Gas Fee. What is Gwei?
When designing Ethereum, $ETH was designed to be split into a minimum of 1,000,000,000,000,000,000 pieces (18 zeros), and for ease of calculation, the minimum split unit was set to the unit of measure “wei”. Later, since Gas Fee is usually much less than 1 $ETH, “Gwei” (gigawei) was set to represent the unit of measure for Gas Fee. giga means gigabyte (like gigabyte-GB), and 1 $ETH = 1,000,000,000 Gwei (9 zeros)
What else do you want to learn?