Understanding Gas in Ethereum: Gas Fees, Gas Price, and Gas Limit Explained
In the Ethereum blockchain, gas plays a crucial role in ensuring that transactions and smart contracts are executed efficiently.
Whether you're transferring ETH, interacting with decentralized applications (dApps), or deploying smart contracts, understanding the concepts of gas, gas fees, gas price, and gas limits is essential for optimizing your transactions.
Today I’ll be sharing a detailed breakdown of each of these terms and also how transaction fee in the Ethereum blockchain is calculated.
Gas
Gas refers to the unit of measurement for the computational work required to execute operations, such as transactions or smart contract executions.
On the Ethereum blockchain, each operation or transaction consumes a certain amount of gas. For example, a simple transaction like sending ETH to another address costs 21,000 gas units, while more complex transactions like minting an NFT require more gas.
Gas Price
The gas price is the amount of Ether (ETH) you're willing to pay for each unit of gas. It’s typically denominated in Gwei, where:
1 Gwei = 0.000000001 ETH
You can set gas prices based on how quickly you want your transaction to be processed. Higher gas prices typically result in faster transactions, as validators prioritize higher-paying transactions.
Gas Fees
Gas fees are the costs associated with executing transactions or smart contracts on the blockchain. They are paid to validators who process and validate transactions.
Gas fees also help prevent network abuse by ensuring that users pay for the computational resources they consume.
Gas fees are determined by supply and demand dynamics within the blockchain network and can fluctuate based on network congestion.
When the network is congested, gas prices tend to increase due to increased competition for transaction processing.
Ethereum introduced EIP-1559 as part of the London hard fork in August 2021, which changed how gas fees work:
Base Fee: A mandatory, algorithmically determined fee that adjusts according to network congestion. It is burned (removed from circulation) rather than paid to validators, which aims to make Ethereum more deflationary.
Priority Fee (Tip): An optional fee that users can include to incentivize validators to prioritize their transactions. This is added on top of the base fee and goes directly to validators.
Gas Limits
The gas limit is the maximum amount of gas a user is willing to spend on a transaction.
It acts as a safety measure to prevent transactions or smart contracts from consuming more gas than the user is willing to pay for, which could happen due to unexpected behaviour or bugs.
Calculating Transaction Fees in Ethereum
From the image above, I’m sending 0.01 SapolioETH from one account to another. The transaction requires 21,000 units of gas, and the gas price is set at 31.948026995 Gwei.
To calculate the transaction fee:
Transaction Fee = Gas Price × Gas Units
In this case:
Transaction Fee = 31.948026995 Gwei × 21,000 units
\= 670,908.56689 Gwei
≈ 0.00067090856689 ETH
Note: The actual gas used may be less than the gas limit set for the transaction. In this case, the unused gas is refunded to the sender.
Understanding these concepts helps users optimize their transactions and manage costs effectively when interacting with the Ethereum network.
Subscribe to my newsletter
Read articles from Zainab Wahab directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by