What are gas fees?

David Liu

May 6, 2024

Ethereum's gas fees, critical for network operation, are shaped by transaction complexity and network demand, influencing transaction inclusion and block validation.

What are gas fees?

Cryptocurrency transactions involve specific costs known as "gas fees," which are essential for the processing and validation of activities on a blockchain network. These fees ensure that transactions are executed securely and efficiently. This blog delves into the details of gas fees, explaining their purpose, how they are charged, the method to calculate them, and strategies to minimize them during transactions, providing a comprehensive understanding for both newcomers and seasoned crypto users.

How do gas fees work in crypto?

On the Ethereum network, every action—whether processing transactions, deploying decentralized applications (dapps), or trading non-fungible tokens (NFTs)—requires a certain amount of gas, which quantifies the computational effort needed. These Ethereum gas fees are denoted in a small unit of ether called "gwei." During periods of high network traffic, which can occur with increased transaction fees from activities like DeFi exchanges or NFT mintings, the base fee, introduced in the EIP-1559 update, dynamically adjusts to help manage congestion. Users can also opt to pay a "priority fee" to expedite their transactions, which is especially useful in a network still transitioning from proof-of-work to proof-of-stake mechanisms. This priority fee serves as an incentive for miners and validators to process transactions swiftly, thereby reducing delays and preventing the network from spamming. This system ensures that whether for simple ether transfers or complex interactions with decentralized applications, the Ethereum blockchain remains efficient and robust.

Gas Fees in Ether: Gas fees are denominated in Ethereum's native currency, ether (ETH). Typically, these fees are expressed in gwei, which is a subdivision of ETH. One gwei is equivalent to one billionth of an ETH (0.000000001 ETH or 10^-9 ETH). To simplify, instead of stating that your gas costs 0.000000001 ether, you can simply say that your gas costs 1 gwei. The term "gwei" is a contraction of "giga-wei," signifying "billion wei." Wei, in turn, is named after Wei Dai, the creator of b-money, and represents the smallest unit of ETH.

How are gas fees charged?

The amount of gas fees charged for Ethereum transactions depends significantly on the complexity of the transaction and the current network demand for transaction processing capacity, as managed by the Ethereum Virtual Machine (EVM). Simple transactions, such as transferring ETH, require less computational power and consequently incur lower fees. Conversely, complex transactions that involve executing multiple operations or smart contracts through the EVM require more computational work and therefore higher fees. Network congestion plays a crucial role as well; during peak times when many users are transacting, transaction costs can spike.

To counteract this, especially post-London upgrade, users can opt to pay a higher eth gas fee to prioritize their transactions, leveraging the dynamic fee structure introduced to improve transaction speed and scalability. This is particularly useful for time-sensitive operations and is a critical component in maintaining efficiency as the network moves towards more sustainable models like proof-of-stake (PoS) with "The Merge." Opting for higher fees during such times isn’t just about expediting transactions but also about ensuring that crucial transactions are verified promptly despite high network demand.

How to calculate gas fees?

Calculating a gas fee requires an understanding of two key components: the gas limit and the gas price. The gas limit is the maximum amount of gas you’re willing to use for your transaction, serving as a cap to prevent runaway costs. The gas price is the amount of cryptocurrency you are willing to pay per unit of gas. The total gas fee is then calculated by multiplying the gas price by the amount of gas used in the transaction. Blockchain networks usually provide estimators and calculators that factor in current network conditions to help users predict the required fee for their transactions accurately.

A transaction that covers only the base fee is technically valid but unlikely to be included since it provides no incentive for validators to choose it over other transactions. The optimal priority fee depends on the network's current demand. When demand is high, a higher priority fee may be necessary, whereas lower demand allows for lower fees.

For example, suppose Jordan needs to pay Taylor 1 ETH. This transaction requires 21,000 units of gas, and the base fee is 10 gwei. Jordan includes a 2 gwei tip. The total fee is calculated as follows: 21,000 * (10 + 2) = 252,000 gwei (0.000252 ETH). Consequently, Jordan's account will be debited by 1.000252 ETH, Taylor will receive 1.0000 ETH, and the validator will receive a 0.000042 ETH tip, while the base fee of 0.00021 ETH is burned.

Base Fee: Each block has a base fee that serves as a minimum price requirement for inclusion. The base fee is determined by previous blocks rather than the current one, enhancing fee predictability for users. This fee increases by a maximum of 12.5% per block if the target block size is exceeded, discouraging sustained high block sizes.

To illustrate, for a transaction on block number 9, a wallet informs the user that the maximum base fee for the next block is 202.7 gwei * 112.5%, resulting in 228.1 gwei. Extended periods of full blocks are unlikely due to the rapid increase in the base fee preceding a full block.

Priority Fee (Tips): Priority fees incentivize validators to include transactions in blocks. Without tips, validators might find it economically viable to mine empty blocks, as the block reward would be the same. Even small tips provide some incentive for validators to include transactions, and higher tips can prioritize a transaction over others in the same block.

Max Fee: Users can specify a maximum limit they are willing to pay for a transaction's execution, known as maxFeePerGas. To execute a transaction, the max fee must exceed the sum of the base fee and tip. The sender is refunded the difference between the max fee and the sum of the base fee and tip.

Block Size: Each block has a target size of 15 million gas, but block sizes can adjust according to network demand, up to a limit of 30 million gas (2x the target block size). The protocol maintains an average block size of 15 million through tâtonnement, adjusting the base fee based on how far the current block size deviates from the target.

How can I avoid high gas fees when making a cryptocurrency transaction?

To avoid high gas fees, users should consider transacting during off-peak hours when there is less demand on the network, potentially lowering the base fee. Leveraging Layer 2 solutions or other scaling solutions like Polygon can also significantly reduce gas costs while ensuring faster transaction confirmations. Tools and platforms providing real-time data on gas prices, such as gas trackers on Etherscan, are invaluable for planning when to execute transactions economically.

Start your Web3 Development with Uniblock

Use our full suite of products to help jumpstart your development into Web3.
Try Uniblock today for free!

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Block quote

Ordered list

  1. Item 1
  2. Item 2
  3. Item 3

Unordered list

  • Item A
  • Item B
  • Item C

Text link

Bold text

Emphasis

Superscript

Subscript

Related posts

We haven't published any posts