🎉🧪 You can now become an official Cryptotester member by minting the new Tester Membership NFTs. 🥳🎊
Click here for details ⇗

Logo CryptotestersLogo Cryptotesters

Hub

Academy

Understanding Ethereum Transaction fees: What is Ethereum gas?

Emanuel Coen

almost 2 years ago ·

7 min read

cryptotesters podcast image

If you’re new to Ethereum and have used an Ethereum wallet to send a transaction or to interact with a decentralized application, you have probably noticed that you had to pay a fee for each transaction.

If you have sent several transactions you might also have noticed that this fee fluctuates. It’s important to understand how Ethereum fees work because when you’re using a Blockchain network, you can’t simply rely on someone fixing problems for you. If you don’t want to overpay or underpay for a transaction it’s important to understand how Ethereum fees come about and how to pay just enough to get your transactions confirmed.

Ethereum_fee.png How fees are displayed to the user in Argent and Bitwala

Contrary to what you might think, the fee you’re paying doesn’t go to the wallet provider whose interface you’re using. Instead it goes to miners.

Why do Ethereum fees exist?

Miners on the Ethereum network, perform computations and validate transactions. These transactions are bundled in blocks by miners and get appended to the Blockchain.

Once a transaction is part of a block on the Ethereum Blockchain it is considered final, as changing the transaction retrospectively is virtually impossible.

In return for their service, miners receive a block reward for each block they mine as well as the sum of all transaction fees users attached to their transactions.

The wallet you’re using merely picks a fee based on what it thinks is the right amount to get your transaction validated by miners in a reasonable time frame.

So why does the fee change?

The simple answer is: fees change based on supply & demand. Blockspace in Ethereum blocks is limited. The demand on the other hand fluctuates. In periods where many users want to get their transaction mined (say in a bull market when people urgently want to send Ether to an exchange), the demand will surpass the supply of blockspace.

This forms a fee market. Once a transaction is signed by your wallet keys’ it is sent to the ‘mempool’(or transaction pool), where miners pick it up, put it in a block and try to validate it as fast as possible. In times where the mempool is full of transactions, miners naturally prioritize those transactions with higher fees as they are more profitable.

post-mempool-intro-process.png

To come up with a fee suggestion when a user wants to initiate a transfer, wallets like Metamask or Argent use software to analyze how much fees were paid in recent blocks and make an informed guess based on it. They then either pick a fee for the user or present several options to the user and let them choose themselves.

What is Ethereum gas?

Now that you understood the basics of Ethereum transaction fees, the lifecycle of a transaction and the fee market let’s look at what gas is. When you send a transaction, the fee is displayed in Ether (ETH) terms or even in dollars. The Ethereum network however, measures fees in gas. Gas measures how computationally expensive a transaction is.

As you might know the Ethereum network doesn’t just handle simple send transactions (e.g sending Ether to a friend) but also more complex smart contract interactions (e.g swapping Ether for Dai on a decentralized exchange).

This characteristic of being able to execute code is why Ethereum is sometimes referred to as a world computer; a distributed computer that runs on thousands of machines distributed over the globe.

To run this code locally these mining nodes have to run what is called the Ethereum Virtual Machine (EVM). The EVM is an emulation of a computer system. Any operation in the EVM consumes CPU cycles, disk access, memory of the hosting machine (which carries a cost). In order to prevent "overload" of the host and mitigate a potential attack vector, each operation on the EVM has a cost. This cost is paid via Ethereum 'gas'.

Each operation or step that a miner performs when running the code has a set gas cost, so if a malicious user crafted a smart contract that went into an infinite loop, each loop would consume some gas and eventually run into the limit, at which point the EVM would abort the execution of this contract. So the user would just pay for nothing making an attack not worthwhile.

Essentially, the larger, more complex a smart contract is and the more operations it performs, the more expensive it becomes to run it.

How is the price of an Ethereum transaction calculated?

There are many key components to a transaction that are important to understand. Here’s an overview.

Ethereum_Fees.png

Having defined these terms, we can show how the cost of an Ethereum transaction is derived.

As we established before, each operation on the Ethereum network consumes a set amount of gas. For example, a transfer of Ether (ETH) consumes 21,000 gas.Ether is a special case because it is Ethereum’s native asset and so Ether transfers all share the same cost. Other assets such as USDT, YFI or SNX (called ERC-20 tokens) are encoded in smart contracts and so the amount of gas you need to execute a send transfer can vary a little bit.

Now how much will we pay per gas for the Ether transfer? Let’s say we decide to pay 30 Gwei ( Gwei is the sub-unit of Ether). If we multiply 30 (price per gas) *21,000 (gas limit), we get 630,000 Gwei or 0,00063 Ether or $0.15cts in dollar terms at the time of writing. So that’s how much the transaction will cost us.

Understanding an Ethereum transaction status

The best way to track a transaction once it has left your wallet is to use a block explorer like Etherscan. Simply put, a block explorer is a graphical interface to visualize Ethereum transactions and the state of the ledger. Like a search engine for the Ethereum Blockchain. You can for example paste your own Ethereum wallet address into the search bar and it will show your account balance, your transaction history and lots of other relevant information.

EtherTrasnfer_Etherscan.jpg

This is how an Ether transfer looks like in Etherscan. Let’s go through the information provided one-by-one.

  1. Transaction Hash: A unique identifier that can be used to locate a specific transaction.
  2. Block: The block number that the transaction was included in.
  3. Timestamp: The time at which the block was mined in UTC.
  4. From & To: The account that originally sent the transaction, the account that receives.
  5. Transaction Fee: The amount of Ether paid to the miner for processing the transaction, which is calculated by multiplying the amount of gas used by the gas price.
  6. Gas Limit: The upper limit of how much computational work and storage the sender is willing to expend on the transaction.
  7. Gas Used by Transaction: The amount of computational work and storage used in the transaction.
  8. Gas Price: The amount of Ether per unit of gas the user is willing to pay for the transaction, commonly denoted in a subunit of Ether known as Gwei. 1 Gwei = 1x10^-9 Ether.
  9. Nonce: The count of transactions sent out of the account. The number is initialized at 0 and is incremented by 1 for each transaction sent.
  10. Input Data: Information that is passed to a smart contract when a transaction is sent to its address.

Now that you have a solid understanding of how an Ethereum transaction works and how to look at it on Etherscan, let’s try to understand common problems users encounter when using Ethereum and how to avoid them.

Why is my Ethereum transaction pending?

Most often when you send a transaction, you’ll use the default gas suggestions of your wallet. The problem however, is that these suggestions can be inaccurate. The fee market moves fast and what might have been a sufficiently high fee a couple of blocks ago, might not be enough to get your transaction confirmed in the current block.

If this is the case, you will have to wait a long time until your transaction gets mined by a miner. This is not a problem per se. If you’re not in a time rush and don’t want to overpay for your transaction it is actually the right approach. However, the problem occurs when you want to send a new transaction while your old transaction has not been confirmed.

This is because every transaction has a nonce, a count of every transaction originating from your account which starts at 0 and keeps incrementing. While you can technically send a new transaction while an old one is not confirmed, it will most probably fail or remain pending.

Users most often encounter this problem, when they interact with a decentralized exchange or other decentralized application (dapp) where they have to complete several transactions in a row (e.g approve a token, swap token). For the token swap to succeed, the first transaction needs to go through. Many users don’t realize that a transaction is pending and proceed with the second one until they get frustrated at some point.

What can I do when my Ethereum transaction is pending or failed?

You can do a few things to prevent this from happening. First of all you can go to a site like Ethereum Gas Station or Ethereum Gas Watch before sending a transaction to get extremely accurate real-time gas price estimates. If you find it annoying to go to a website every time before you send an Ethereum transaction you can also download the Ethereum Gas Station networks Chrome extension, so you view the gas estimates in your browser bar at all times.

Using those estimates your transactions should go through without any problems most of the time! If it’s too late and the transaction is already sent, you can do two things.

Using a wallet like Metamask you can bump up the transaction fee retrospectively. If you want to flat out cancel a transaction because you have changed your mind, you can also do it using Metamask’s built-in ‘cancel’ option. If you use other wallets like Argent or Dharma there is currently no way to cancel or speed-up your Ethereum transactions but these wallets have sophisticated techniques to send your transactions through anyway.

Follow us on Twitter or come in our Telegram channel if you have any questions or would like to discuss this blog post!

Emanuel Coen

almost 2 years ago ·

7 min read


Latest Content

July 2022

Social network goes 3.0

July 2022

Azuro Protocol: Can the betting industry...

April 2022

Polynomial The New DeFi Derivatives Powe...

March 2022

Courtyard: Bringing Billions of Dollars ...

February 2022

The Rise of Music NFTs - Will this unlea...

January 2022

Deep dive into Perpetual Protocol v2

January 2022

Deep dive into Treasure DAO

January 2022

Why you should use Cowswap for all your ...

Cryptotesters Logo

We are a multi-faceted team of crypto enthusiasts based in Berlin.

© 2021 cryptotesters UG

Stay up to date!  Sign-up for a monthly roundup of the newest crypto products


Products

Cryptocurrency exchanges

Crypto wallet guide

Crypto savings accounts

Defi lending rates

Crypto cards

Exclusive crypto deals

Ethereum staking

Resources

Articles

Reviews

Podcasts

Tutorials


Twitter logoLinkedIn logoFacebook logo
Cryptotesters Logo

We are a multi-faceted team of crypto enthusiasts based in Berlin.

© 2021 cryptotesters UG