10 months ago ·
7 min read
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.
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.
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.
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.
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.
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.
There are many key components to a transaction that are important to understand. Here’s an overview.
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.
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.
This is how an Ether transfer looks like in Etherscan. Let’s go through the information provided one-by-one.
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.
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.
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.
10 months ago ·
7 min read
We are a multi-faceted team of crypto enthusiasts based in Berlin.
© 2021 cryptotesters UG
How to buy bitcoin
Crypto wallet guide
Crypto savings accounts
Defi lending rates
Exclusive crypto deals