
Ethereum transaction fees explained
Lately, transaction fees on the Ethereum network have skyrocketed. As defi applications like Uniswap increase in popularity, it’s become ever more apparent that the network is completely congested — and with this congestion comes increasing transaction fees.
How do transaction fees on Ethereum work?
The system of transaction fees in Ethereum differs from Bitcoin quite a lot. It is measured in units of something called Gas.
You have to keep in mind that apart from being able to send simple transactions from address A to address B (like in bitcoin) — Ethereum also powers smart contracts which are applications written in a programming language called Solidity.
These applications cost gas to run and the amount of gas needed to run a specific function or application depends on the complexity of the application and what operations it does.
Each time a transaction invokes a smart contract on the blockchain this code needs to be executed by every full node to verify the results of the transaction.
Because each line of code in a smart contract involves some type of operation it will cost CPU cycles on every node and CPU cycles are not free. Therefore the creators of Ethereum came up with the idea to use Gas as a unit to measure how much each operation should cost.
Gas in more detail
Gas is the unit of measurement used when allocating resources in the Ethereum virtual machine (EVM). Resources are allocated in the EVM as soon as any instruction or operation is performed, like adding or subtracting two numbers.
So whenever you interact with a smart contract on the blockchain by sending a transaction to it you should keep in mind that behind-the-scenes code is being invoked in the EVM.
The price of one unit of Gas is dynamic and changes based on network congestion. The gas price is often measured in smaller units of Ethereum, for example, Wei and Gwei. As described above each operation in a smart contract costs Gas. As an example, we could take a look at this simple function below.
function doSomeMath(int a, int b){
a + b;
b / a;
b * a;
b - a;
}
Each operation in this function takes X amount of gas to run. In total the cost of running the function above would be 3 + 5 + 5 + 3 = 16 gas. For the sake of simplicity, let us imagine that 1 gas costs 100 wei today. That would mean that the transaction in total would cost 16 gas * 100 wei = 1600 wei.
Each operation that you can perform has an opcode assigned to it. If you want to see a table with all operations and their respective costs you can find one here.
Gas price & gas limit
When sending transactions on Ethereum most wallets will allow you to set a gas price and a gas limit manually.
Gas price
When setting the gas price manually you are telling the network how much you are willing to pay for each unit of gas. If setting a too low of a gas price the transaction might take a long time before it gets included in a block. Therefore you should check what the current gas prices are on any website that keeps track of this before you initiate any transaction. A popular website in the community for these kinds of stats is ethgasstation.info
Gas limit
This gas limit is also important, it sets a hard limit on the maximum amount of units of gas that you are willing to pay for this transaction. In many cases, it unfortunately, won’t be very obvious how much gas the transaction will cost. Because of this, having an option to set a gas limit is very important.
Keep in mind though, if the transaction burns more gas than the limit you’ve set you will still pay the gas fees up to this limit but the transaction will not fully complete. In such a case you will have wasted money by burning gas for nothing.