Gas Unveiled: Understanding the Key Player in Ethereum Transactions.

Oluwakemi Atoyebi
Web3 Writers Guild
Published in
6 min readFeb 6, 2024

The concept of Gas.

Photo by Erik Mclean on Unsplash

Fuel is essential for the operation of a fuel-efficient vehicle, much like gas is essential for the operation of Ethereum. Gas refers to the unit that measures the amount of computational effort required to execute specific operations on the Ethereum network. The computational effort is directly related to the complexity or energy intensity required to process transactions or execute smart contracts on the Ethereum network. The more intricate or resource-intensive the task, the higher the amount of gas needed, reflecting the computational workload. This mechanism ensures the Ethereum network operates smoothly and serves as an incentive for users to employ it judiciously.

Gas should not be mistaken for ethers, the main currency of Ethereum. Instead, gas is a virtual currency you use to power actions on the Ethereum network. Expanding on the car analogy, just as you don’t directly pay with money for fuel, but instead exchange money for a certain amount of fuel, in Ethereum, you exchange ethers (the main currency) for a certain amount of gas. Gas has its own price, and you use ethers to pay for it, enabling you to perform transactions and run programs on the Ethereum network. So, similar to trading money for fuel to power your car, in Ethereum, you trade ethers for gas to execute actions and processes.

What are gas fees?

The gas fee on Ethereum is like paying for actions on the network. It’s calculated by taking the amount of ‘gas’ needed for an operation and multiplying it by the cost per unit of gas. It is usually paid in ethers. This fee is similar to the transaction fees you might pay with your bank app, but there’s a difference.

On Ethereum, you pay the gas fee whether your action succeeds or not. It’s like buying a ticket for a ride, you pay for the chance to try, even if the ride doesn’t go as planned. This brings us to the concept of gas price which is the price per unit of gas, quoted in gwei(gigawei) — an ether unit. Think of gas price as the price per liter of fuel, and the gas fee as the total cost for all the fuel you use for a trip.

Importance of gas fees to the Ethereum network

  • Control: It acts as a safeguard by constraining the amount of computation a transaction can demand within the Ethereum network. The open-ended (Turing-complete) computational framework requires a form of regulation to prevent potential denial-of-service attacks or unintentional resource-intensive transactions.

Turing complete: This term suggests that a system has the capability to execute any imaginable calculation or program. However, it brings along a challenge known as the halting problem. This problem revolves around the difficulty of determining, in advance, whether a program will eventually stop or continue running indefinitely. In simpler terms, it’s like predicting if a computer program will finish its task or keep running forever.

  • Security: these fees act as a crucial defense, shielding the system from poorly designed smart contracts that could potentially cause accidental or hostile infinite loops, posing security risks. Beyond this, gas fees act as a deterrent against malicious actors aiming to flood the network with spam, reinforcing the robustness and resilience of the Ethereum system.
  • Incentive: It serves as a powerful way to encourage validators to stay engaged in verifying transactions and upholding network security. Validators, who play a vital role in the Ethereum network by voting on blocks (“attestation”) and suggesting new blocks for the transaction chain, receive a fraction of the gas fees (priority fee/tip) as their well-earned reward.

Calculating Gas Fees: The Breakdown

Ethereum’s approach to gas fee calculations evolved with two significant network upgrades: Pre and Post-London-Upgrade.

Before the London upgrade, gas fees followed a first-price auction model. Users had to bid for their transactions to be included in the next block, specifying the gas price they were willing to pay. However, this model proved flawed as the Ethereum network got busier, leading to unnatural spikes in gas prices due to users overbidding each other. The gas fee was determined using a straightforward formula:

gas fees = gas spent * gas price

  • Gas Spent is the total amount of gas (in gas units) that was used to execute the transaction
  • Gas Price is the amount of ether you’re willing to pay per gas unit of execution.

The post-London upgrade, specifically EIP-1559, introduced the concept of the base fee. The total gas was divided into two components: the base fee and the priority fee (tip). The gas fee was calculated using this formula:

Total Fee = Gas unit (limits) * (Base fee + Tip).

Now, let’s take a closer look at these concepts:

Base fee: is set by the protocol and it refers to the minimum amount of gas required to include a transaction on the Ethereum blockchain. It is set per block and can vary based on network demand. If the network is more than 50% busy, the base fee increases; otherwise, it decreases. The change in the base fee is capped at 12.5% per block. For example, if the current base fee is 202.7 gwei, it can increase to a maximum of 228.1 gwei in the next block. This system aims to regulate network congestion and enhance the predictability of transaction fees. This fee is usually “burned” or removed from circulation once the block is created.

You might wonder, why is the base fee burned?

To deter miners from teaming up to unfairly increase the minimum fee (base fee) just for their gain, only the tip you give directly to the miner is their reward. The entire base fee, instead of going to the miner, is burned or destroyed. This is why it’s called the fork — “the fire of London”, referencing the Great Fire of London, as it’s a way of getting rid of the base fee like the fire got rid of things in history.

Priority fee: is a tip that you add to the base fee to make your transaction attractive to validators so that they choose it for inclusion in the next block. The value of the priority fee is set by the users. The more busy the network gets, users must offer higher tip amounts to try and outbid other users’ transactions

It’s important to note that many wallet providers automatically set a suggested transaction fee (base fee + recommended priority fee), alleviating users from the complexities of this calculation.

An image of Metamask wallet with a recommended gas fee
Metamask automatically configures the transaction fee.

To conclude this section, let’s explore the concepts of max fee and gas limit and understand their relevance to you.

The max fee is the highest amount a user is willing to pay for their transaction to be executed. It’s an optional parameter called maxFeePerGas. To get a transaction processed, the max fee must be greater than the combined base fee and tip. The sender of the transaction usually receives a refund equal to the difference between the max fee and the total of the base fee and tip.

Adjusting gas fees on Metamask to optimize the attractiveness of your transaction.

On the other hand, the gas limit is the maximum quantity of gas units the sender is willing to purchase to complete the transaction. More complex transactions require higher limits. Setting too low a limit may cause transaction failure, consuming the gas. Conversely, a higher-than-needed limit refunds the excess gas to the user. For instance, with a limit of 40,000 for a transaction requiring 21,000, 19,000 units would be refunded.

Adjusting gas limit on Metamask.

In conclusion, gas remains the vital fuel powering Ethereum’s decentralized engine, comparable to fuel for a vehicle. It dictates the smooth operation of transactions, ensuring control, security, and incentivizing validators to maintain the network’s integrity.

--

--