Understanding Ethereum fees: How gas works
Ethereum transaction fees hit another all-time high (ATH) this week, with miners earning a record $500,000 in fees in a single hour.
#Ethereum miners earned over $500,000 USD in transaction fees in the past hour.
That is a new record high for a single hour (anomalous transaction fees earlier this year excluded).
— glassnode (@glassnode) September 1, 2020
While this is good news for Ethereum miners though, it’s a different story for users who are paying higher fees and longer wait times, with congestion on the network causing more unconfirmed transactions.
Many in the community have subsequently raised concerns about the network’s stability and whether the fees make it unsustainable, particularly as the decentralised finance (DeFi) boom – which many argue is causing high fees – shows no sign of abating.
In order to better understand this, let’s first break down how Ethereum transaction fees work.
How Ethereum fees work
Very simply, Ethereum runs on something called gas. Gas is a unit of measurement for the amount of computational power required to execute certain operations on the Ethereum blockchain. Every operation, be it a transaction or smart contract execution, requires some amount of gas. Gas is used to calculate the amount of fees owed to the network in order to execute the operation. Miners then receive compensation in Ether, which is equivalent to the total amount of gas it took them to execute a complete operation.
This is different to a cryptocurrency such as Bitcoin. This is because the Bitcoin blockchain is only geared to facilitate monetary transactions, with no way to add “conditions” to a transaction. For example, if you send someone 1 BTC, you wouldn’t be able to impose a condition on the transaction, like letting the recipient know they’ll only receive the money if they perform certain tasks. Smart contracts – which are generally run on the Ethereum blockchain – do allow for these types of conditions to be attached to a transaction. Because of this, smart contracts are handy for exchanges of property, shares or money, in a transparent manner without the need for a middleman, like a lawyer.
The table below from the Ethereum Yellow Paper indicates roughly how much a specific instruction will cost you in gas. According to the table, every transaction requires at least 21,000 gas.
Let’s use a popular analogy to better understand gas. Imagine you’re about to set off on a road trip. Before you go, you’d like to fill your car with fuel (or gas). You go to the gas station and specify how much gas you want to fill your car with. After your car’s been filled, you pay the gas station the amount of money you owe them for the gas.
Now, think of driving the car as being the operation you want to execute (like executing a function of a smart contract). The fuel in your car is the gas and the gas station is the miner. The money you paid the gas station is the miner fees. Therefore, technically, gas is the fuel powering the Ethereum network.
Importantly though, fuel isn’t a currency on its own. It needs to be bought and denominated into a currency, like the Dollar or Euro. The same goes for gas – in order for it to be paid, it needs to have its value expressed in Ether, the underlying cryptocurrency of the Ethereum network. There is no fixed price to convert gas to Ether, which means it’s up to buyers and sellers (miners) to come up with a price suitable to both parties.
In order to execute a transaction on the Ethereum network, the sender needs to specify a “gas limit” before submitting it to the network. The gas limit is the maximum amount someone is willing to pay for their instructions (or transaction) to go through and be processed.
Miners who process these transactions have a few options when they receive a pending transaction. First, they could accept the transaction by processing the instructions with their computers and decide to keep the attached fee set by the sender. Secondly, they could also refund some of the gas to the sender if the sender set a higher gas limit than was necessary for the transaction. On the other hand, they could decline the transaction if a sender sets a lower gas limit than what the market is paying at the time.
If a transaction’s instructions run out of gas mid-execution while a miner is processing it, it’s then “reverted back to its original state”, meaning the transaction has been returned to the sender. Regardless, the sender must still pay a fee to miners to compensate them for the computational power they spent processing the transaction, even if it was partially completed. Miners must also add the transaction to the blockchain, even if it wasn’t fully executed. If the sender specified a higher gas limit than was necessary, the miner would refund the difference to the sender.
This mechanism has its flaws, especially when it comes to transactions with high gas limits. For Bitcoin, paying more usually means a faster transaction time. But in Ethereum’s case, for each block on the Ethereum network, miners are bound by the maximum “block gas limit” which determines the maximum amount of gas that can be spent per block. With the current gas limit set at roughly 10,000,000 gas, miners are less inclined to include transactions with high gas limits as it would waste part of the block gas limit. Generally, such high gas transactions are likely to be refunded by the miner, resulting in miners being more interested in taking on smaller transactions.
For Ethereum to truly work as a world computer, fees on the network need to be tiny. Therefore, in order to pay these fees, Ether would need to be denominated in much smaller amounts. The most widely used denomination of Ether is “gwei”, also known as nanoether. 1 gwei = 0.000000001 ether (10^-9).
How to calculate Ethereum transaction fees
There are a number of ways to calculate the fees necessary to execute a transaction. Theoretically, due to the way the network is set up, a sender could select an arbitrary fee, but that wouldn’t really work since miners are incentivised by fees.
There are a variety of gas calculators available online, offering users a general idea of how much gas their transaction requires. Ethereum Gas Station, for example, is heralded for its accuracy and user-friendly interface. It’s important to remember that recommended prices are only estimated amounts that are subject to change.
It is also possible to determine transaction fees without an online calculator. A sender would need to know how much gas each operation on Ethereum requires, along with a basic understanding of the average market rate for gas prices.
Ethereum’s auction mechanism
Ethereum uses a “first price auction” system to price gas. For this to work, every sender submits a bid (or a gas limit) for how much they’re willing to pay. Miners then pick up desirable transactions and include them in the next block. Theoretically, this allows senders to prioritise their transactions by paying a higher fee, while also saving ETH through refunds. However, in reality, there are more significant flaws.
Usually, if a miner selects transactions with the highest bids, this causes senders to set even higher bids on other transactions they make. Due to a lack of transparency, there’s no way for someone to know what bids came with other pending transactions, which can result in overpaying. According to Eric Conner, founder of Ethhub, many users overpay by more than five times what was necessary. Luckily, there are improvements in the works with Ethereum 2.0, as users can expect to see major changes to the network sometime later this year. Arguably, one of the most notable changes will see Ethereum’s consensus mechanism shift from proof-of-work (PoW) to proof-of-stake (PoS).
How DeFi is upping the ante
Demand for Ether has increased significantly since mid-June, owing in part to an increasing number of users utilising DeFi platforms such as Uniswap, ultimately bottlenecking Ethereum’s network.
As a result, transaction fees have reached record highs and have even outpaced bitcoin.
The gap is now up to $1 million a day. pic.twitter.com/MTyjVYT4b8
— Cryptowatch (@cryptowat_ch) August 12, 2020
While these increased fees are not ideal for users, Ethereum network fundamentals paint a healthy picture. The hash rate, for example, remains high. While Ethereum remains a PoW blockchain (for now), the hash rate is an important metric for blockchain security.
One of the biggest hurdles Ethereum (and Bitcoin) faces is scalability. In order for the network to effectively handle more users and increased functionality, its processing power would need to improve significantly.
This is why the most-anticipated change expected in Ethereum 2.0 is the consensus mechanism shift from PoW to PoS. The new blockchain protocol should address the decentralisation challenge by allowing more individual validators to participate and receive a return for maintaining the network. This should have an impact on fees, bringing them back down to a more reasonable level for the average user.
All in all, it’s not a bad time to be an Ethereum miner, though. What are you most excited about for Ethereum 2.0? Do you think high fees could cause a long-term issue? Let us know on Twitter.
Originally published on 18 June 2020. Updated on 4 September 2020.