Ethereum Gas Fees Explained
Have you ever been listening to crypto-related content and then all of the sudden gas is being discussed? No, you didn’t miss anything, there is a thing called gas fees. They are charged by certain blockchains to pay for the services that they provide. Think of gas fees as fuel for a vehicle. This guide is your road map to gas fees. Buckle up - we are going to fill your ‘Crypto tank’ full of ‘gas fee’ knowledge.
What are Gas Fees?
Gas is a term used in crypto. Gas fees are compensation to cover work computed to complete transactions. Gas fees can have different names or functions based on the blockchain being used and not all blockchains use gas fees in the same sense that the Ethereum blockchain does, which we are going to discuss here.
What is EVM?
For this guide, we will focus on Ethereum’s Virtual Machine (EVM). At the time of writing this guide, EVM is Proof-of-Work Layer 1 blockchain (which is planning to switch to Proof-of-Stake in the near future) whose native coin is ether aka ETH. Proof-of-Work blockchains have a person verifying, validating, and completing each transaction.
How Does EVM Work, What is Proof-of-Work?
Miners, validators, and node operators are the stakeholders performing the ‘work’ in these transactions that need fees. The pay here is not measured by the hour but by work performed. People or companies who contribute work to completing transactions receive ETH as a reward. Therein, we have a proof-of-work style consensus and gas fees. The larger the transaction, or, the more block space it takes, the larger the gas fee will be. Transaction gas fees can also get much larger when the network is congested.
Ethereum's necessity to use a Proof-of-Work style blockchain is best described in their ‘Yellow Paper’. The latest edition was released in April 2022:
“The mining proof-of-work (PoW) exists as a cryptographically secure nonce that proves beyond reasonable doubt that a particular amount of computation has been expended in the determination of some token value n. It is utilized to enforce blockchain security by giving meaning and credence to the notion of difficulty (and, by extension, total difficulty). However, since mining new blocks comes with an attached reward, the proof-of-work not only functions as a method of securing confidence that the blockchain will remain canonical into the future, but also as a wealth distribution mechanism.”
How Are Gas Fees Calculated?
Now that we have more context for the proof-of-work blockchain consensus, we can take a look at how gas fees are broken down. Fortunately for us, Ethereum provides great tools for learning about gas fees! Here are two tables that show how gas fees are calculated:
The table above demonstrates how every transaction has a base fee - this base fee is calculated based on the size of the transaction in relation to how many transactions are processed in each block. We can see that the maximum base fee is a 12.5% increase which remains at that maximum until the target block is reached. The base fee increase then resets and the gas used in previous transactions is burned.
Above we are shown how gas prices could rise to an unfeasible rate by packing as many transactions into each block as possible. This would raise the gas price rate as well as slow down the network. EVM is designed to prevent this from happening, as it would be harmful to the ecosystem as well as consumers.
How To Lower Gas Fees Paid in a Transaction?
Below is an image of a MetaMask Wallet that is about to perform a transaction sending ETH. We’ll use MetaMask as an example because it is a widely adopted custodial wallet of ethereum and related cryptocurrencies.
MetaMask also has options to adjust the gas prices, at your own risk. While the Gas Limit must remain at least 21,000, MetaMask will not allow you to move to the next part of the transaction if the gas limit is below 21,000. However, you will notice sometimes the gas limit value is much higher than 21,000. You can certainly lower that value but it is not promised that the network would be able to complete your transaction anytime soon, thus your transaction may be rejected. In such cases, you would have to return to your wallet and raise the gas limit.
To the left of the gas limit, you see the gas price (GWEI), which is the smallest unit of ETH and is used to pay gas fees. Gwei is short for Gigawei, and 1 ETH is equivalent to 1 billion Gwei. As shown in the image above, 0.03 is the gas price in Gwei, which is a good gas price. Often times when the network is congested you will find that you cannot lower the gas price in Gwei below 1.
In Metamask if you were to accept these fees and proceed to the next screen there is an advanced option that allows you to add a tip, there are also normally options to send the transaction slower at a cheaper rate, or, of course, faster for a higher rate. Often times MetaMask will default to ‘market’ which is right in the middle of the two.
Overview of How EVM Works
Because of EVM’s speed and its ability to execute transactions for cryptocurrencies, sign smart contracts, as well as transactions to transfer and store NFTs (just to name a few of its abilities).
You can find a great 116-page PDF booklet - Ethereum EVM Illustrated on GitHub. The following diagrams are all sourced from the PDF on GitHub (link above) and will help give us a better understanding of the process that one transaction must complete before being confirmed in our wallets. Furthermore, an explanation of why we have to pay gas fees on EVM.
Starting with a basic model of EVM architecture, you can see three main components, immutable, volatile, and persistent.
The EVM code is stored virtually and is necessary for any EVM transaction. The Machine state is the computer used for the transaction. This is where some information is kept to build the stack, as well as the gas, some sort of wallet, or crypto stored on the computer. The third component is the ‘world state’, which is the container that stores data for a transaction.
The following diagram shows the code (transaction) being executed on EVM. This is a great example to show why every transaction executed on EVM requires gas fees to be paid.
As you can see in the diagram there are two World state containers, in the middle, there was some sort of message, on the right container you can see ‘update’.
The way the information flows, the first version of World state is sent in two separate channels to EVM, one with the code and the other is storage. Then a change is made to the smart contract (or some part of the transaction). That change is sent to EVM along with the original World state. The original world state creates another transaction in order to create the updated world state with the updated data. Each time you see a line on the diagram, there is a person executing the task therefore, there is a gas fee paid.
Gas and Fees
Below we have a few more diagrams to show gas fees by the numbers, in a custodial, moc-transaction, and now the technical illustration of how gas fees are computed on EVM.
As you can see below there is a transaction (outside of the world state container) going into the EOA (Externally Owned Account). This would be, for example, your custodial wallet. It is shown that the EOA is sending a message along with the gas fee. Remember there is a gas limit, so each transaction must have a gas limit of 21,000. In the diagram below it appears that the transaction is only to sign a contract. This transaction did not use the limit of 21,000, so the leftover amount is refunded to the EOA. You will never have to pay more gas than required - unless you choose to tip the validator or speed up your transaction.
Below is a basic diagram of how gas is charged throughout various stages of a transaction. You start with the gas available on your computer. The EVM code is embedded in the transaction that you are prompted to execute, there is the first gas fee. The operation or transaction type is put in a stack and saved to internal memory (to save to your computer’s memory there is no gas fee).
However, to move that operation from the stack to the storage on EVM there is a gas fee. There is one more gas fee in this transaction to make the operation a message call, in other words, to set the transaction into action. The diagram below is showing us on a gas-focused scale, the same series of tasks performed in the previous diagram displaying the execution of coding on EVM. The two arrows go from the World state (storage on EVM) to the EVM. One of those arrows (gas fee) are for the transaction data. The other arrow is for the storage on EVM, where the stack with your transaction’s data gets put onto a block.
Key Takeaways and Tools
Gas fees are a bit more complex than they sound. But that is the beauty of the technology, custodial wallets, smart contracts, and blockchain technology - we do not need to fully understand the cryptography behind the EVM or its gas fees in order to use it.
The basic principle is that there is a person verifying, validating, and pushing data along to complete each transaction, and for their work, they are rewarded in ETH. When you simplify the concept, EVM is similar to a bus, a bus needs gas to drive around and pick-up or drop off the people riding in it. The people are like the data. The gas fees are… the fuel the bus would take to drive from destination to destination.
Ethereum is a great provider of information as well as tools to navigate gas fees. Below are the links for a few sites that you can visit to check the average gas fee at that specific moment, you are able to see if the network is congested, maybe you should wait to make your transaction if the gas fees are too high. If you need a transaction to happen fast, then you know you may want to tack on some extra gas fees to get your transaction through in a timely manner.
- Blocknative ETH Gas Estimator
- https://etherscan.io/gastracker
- ETH Gas Station
- https://github.com/takenobu-hs/ethereum-evm-illustrated
- https://ethereum.org/en/
In conclusion, sometimes gas fees can be a pain, sometimes they are very little and well worth the speedy transaction that they paid to make happen. There are many layer one and even layer two blockchains with protocols to be interoperable with EVM and aim to minimize or eliminate gas fees. With everything in crypto, it is best to always do your research when investing your money.