Recommended resources
The freely available resources this lesson will direct you to.
Hello! Welcome to the sixth lesson in our course on building blockchain applications.
In our last lesson, we drew a critical line between Externally Owned Accounts (EOAs), which are controlled by users, and Contract Accounts, which are controlled by code. We established that every action on Ethereum, like the ones needed to interact with your future token, must be initiated by an EOA sending a transaction.
Today, we'll answer the natural follow-up question: what does it cost to send that transaction?
Your goal for this lesson is to explain the role of Ether (ETH), transactions, gas, and gas fees. As a backend developer, you're familiar with the idea that computational resources aren't free—servers cost money to run, and API calls consume resources. Ethereum works on the same principle. Every line of code your smart contract executes will have a real-world cost for your users, so understanding these mechanics is fundamental to writing efficient and user-friendly applications.
Ether (ETH): The Native Currency
The simplest component to understand is Ether (ETH). It is the native cryptocurrency of the Ethereum network. Just as you need dollars to buy things in the US, you need ETH to pay for operations on Ethereum. All transaction fees are paid in ETH.
Because fees can be very small, it's cumbersome to talk about them in fractions of an ETH. Instead, the community uses smaller denominations. The most common one you'll encounter is Gwei, which is short for giga-wei.
- 1 ETH = 1,000,000,000 Gwei (1 billion)
- 1 Gwei = 0.000000001 ETH
Think of Gwei to ETH as cents to a dollar. When setting transaction fees, you will almost always be thinking in Gwei.
What is Gas? The Unit of Computational Work
If ETH is the currency, gas is the unit of measurement for the work being done. Every single operation that can be executed by the Ethereum Virtual Machine (EVM)—from adding two numbers to storing data in a contract—has a fixed cost measured in gas.
- A simple ETH transfer has a fixed cost of 21,000 gas.
- A more complex operation, like interacting with a smart contract, might cost 100,000 gas or more, depending on the computational steps involved.
So, why not just price operations in ETH directly? The key reason is to decouple the cost of computation from the volatile market price of ETH. The computational effort to add two numbers is constant, but the price of ETH can swing wildly. By having a separate unit (gas), the cost of an operation in gas remains stable, while the price of gas (in Gwei) can fluctuate based on network demand.
This is analogous to how electricity is measured. The amount of work your refrigerator does is measured in kilowatt-hours (kWh), a fixed unit of energy. The price you pay per kWh, however, can change.
Let's watch a short clip that introduces this core concept.
What Is GAS? Ethereum HIGH Transaction Fees Explained
The video 'What Is GAS?' by Finematics provides an excellent analogy for gas and explains its role as a unit of measurement for computational effort.
Please watch from 00:22 to 01:22. Focus on how gas is a unit for measuring computation and how every operation has a specific gas cost.
Why Do Gas Fees Exist?
The concept of gas fees is central to Ethereum's security and stability.
- To Prevent Spam and Malicious Code: Since every computation has a cost, it becomes prohibitively expensive for a bad actor to deliberately spam the network with useless transactions. More importantly, it prevents accidental or hostile infinite loops. Because your transaction has a finite amount of gas it can use, a program cannot run forever and bring the entire network to a halt. This is Ethereum's practical solution to the theoretical "Halting Problem" in computer science.
- To Incentivize Validators: Validators (previously known as miners) are the participants who run the hardware that processes transactions and secures the network. The gas fees paid by users serve as their compensation for contributing these computational resources.
The diagram below shows the high-level flow of a transaction, where the sender pays a fee to have a validator process their transaction and include it on the blockchain.

Calculating the Transaction Fee (The Modern Way: EIP-1559)
The way fees are calculated was significantly updated with a change known as EIP-1559. It was designed to make fees more predictable. Instead of a simple single "gas price" bid, the price you pay per unit of gas is now made of two components.
The best way to understand this is to read the official explanation.
Ethereum gas and fees: technical overview
The official Ethereum documentation provides the most accurate and up-to-date explanation of how gas fees are calculated. We'll read the key sections that break down the current fee mechanism.
Please read the following sections on the webpage: Start at the top and read through the introductory sections 'What is gas?' and 'How are gas fees calculated?' Continue with the subsections 'Base fee' and 'Priority fee (tips)'. Focus on understanding the role of the base fee (which is burned) and the priority fee (which goes to the validator).
To summarize the key points from that reading:
The total fee for a transaction is calculated as:
- Base Fee: This is the minimum price per unit of gas required for a transaction to be included in a block. It is set by the protocol and adjusts automatically based on network congestion. If blocks are more than 50% full, the base fee goes up; if they are less than 50% full, it goes down. A critical feature is that the base fee is burned (destroyed), not paid to the validator.
- Priority Fee (Tip): This is an additional fee you add on top of the base fee to incentivize the validator to include your transaction in the block. In times of high congestion, a higher tip can get your transaction processed faster. This fee goes directly to the validator.
Example from the reading: A simple ETH transfer requires 21,000 gas.
- The
base feeis 10 Gwei. - You add a
priority fee(tip) of 2 Gwei.
The price per gas unit is 10 + 2 = 12 Gwei.
The total fee is 21,000 * 12 = 252,000 Gwei (or 0.000252 ETH).
Gas Limit and Max Fee: Your Safety Nets
When you send a transaction, you set two important parameters to protect yourself.
-
Gas Limit: The maximum amount of gas you are willing to let your transaction consume.
- For a simple ETH transfer, the gas limit would be 21,000.
- For a complex contract interaction, your wallet (like MetaMask) will estimate a higher limit, e.g., 150,000.
- What happens if you set it too low? If your transaction runs out of gas mid-execution, it will fail and all state changes will be reverted. However, you still pay the fee for the computational work that was done. The gas is consumed.
- What happens if you set it too high? The transaction will only use the gas it needs, and the unused gas is never charged. You don't pay for gas you don't use.
-
Max Fee Per Gas: The absolute maximum price (Base Fee + Priority Fee) you are willing to pay per unit of gas. This protects you from a sudden spike in the network's base fee while your transaction is pending. You are refunded the difference between your
Max Feeand the actualBase Fee + Tip.
The image below gives a simple breakdown of the difference between Gas Limit and Gas Price.

Test your understanding!
You are deploying a new smart contract. Your wallet estimates it will take 200,000 gas.
- You set a Gas Limit of
250,000. - The block your transaction is included in has a Base Fee of
15 Gwei. - You set a Priority Fee of
2 Gwei.
How much will this transaction cost you in Gwei and ETH? What happens to the unused portion of the Gas Limit?
Show answer
-
Calculate the price per gas unit:
Base Fee + Priority Fee = 15 Gwei + 2 Gwei = 17 Gwei -
Calculate the total fee:
The transaction only used the gas it needed, which was200,000.Gas Used * Price per Gas = 200,000 * 17 Gwei = 3,400,000 Gwei -
Convert to ETH:
3,400,000 Gwei / 1,000,000,000 = 0.0034 ETH
The transaction will cost 0.0034 ETH. The unused portion of the Gas Limit (50,000 gas) is simply ignored. You are not charged for it.
Conclusion
Understanding Ethereum's fee market is essential for any developer in this space. Writing gas-efficient code is a mark of a skilled smart contract developer because it directly saves your users money.
Key Takeaways:
- ETH is the native currency used to pay for everything on the network. Fees are typically denominated in Gwei.
- Gas is the unit of measurement for computational work. Every EVM operation has a fixed gas cost.
- Gas Fees are paid to compensate validators and secure the network from spam.
- The modern fee is
Gas Used * (Base Fee + Priority Fee). The base fee is burned, and the priority fee is a tip to the validator. - The Gas Limit is a safety mechanism to cap the total computation; if a transaction runs out of gas, it fails, but you still pay for the work done.
Preview of the Next Lesson:
Theory is great, but it's time to put it into practice. In the next lesson, you will set up your own MetaMask wallet. This will give you your very own EOA and allow you to connect to an Ethereum testnet—a sandbox environment where you can perform transactions and experience the gas mechanism firsthand without spending any real money.