What Is Gas? Ethereum High Transaction Fees Explained
So what exactly is gas? Why are transaction fees so high at the moment? And what are some of the ways to make the transaction cost lower? You’ll find answers to these questions in this article.
Let’s start with what gas actually is.
What Is Gas
Gas is a unit used for measuring the amount of computational effort required to perform specific actions on the Ethereum blockchain.
The name itself hasn’t been chosen by accident. Similarly to gasoline fueling a car and allowing it to drive, gas on the Ethereum network fuels transactions and allows them to perform different operations.
Every operation on the Ethereum blockchain, or to be precise on the Ethereum Virtual Machine (EVM), has an associated gas cost. For example: adding 2 numbers costs 3 gas; getting the balance of an account — 400 gas; sending a transaction — 21,000 gas.
Smart contracts usually consist of multiple operations that together can cost even hundreds of thousands of gas.
What is interesting is that the gas cost by itself doesn’t tell us how much we have to pay for a particular transaction. To calculate the transaction fee we have to multiply the gas cost by gas price.
The gas price is measured in gwei — a smaller unit than ether where 1 gwei equals 0.000000001 ETH. We can think about it as a major and a minor unit similarly to dollars and cents.
As an example, let’s say we want to send a simple Ethereum transaction and the ETH price is at $1,800. Most of the popular Ethereum wallets such as Metamask estimate necessary gas prices and allow us to choose between fast, medium and slow transaction confirmation speed. Let’s assume that the wallet estimated the gas price to be set to 100 gwei if we want to have a chance of having our transaction confirmed within the next minute.
We can now quickly calculate that we have to pay $3.78 for such a transaction. We multiply the gas cost for sending a transaction — 21,000 gas — and the gas price — 100 gwei. This is equal to 2,100,000 gwei which is 0.0021 ETH. At the ETH price of $1,800, this gives us $3.78.
ETH Price And Gas
It’s worth mentioning that gas is only an abstract unit that exists only inside the EVM and the user always pays for their transactions in ETH.
The main reason for having a separate unit for measuring computational effort is to decouple it from the price of ETH.
This means that the increase in the ETH price should not change the cost of transactions. If the network activity stays the same and the price goes up we should see the gas price going down, so the final transaction cost measured in ETH stays the same in dollar value.
Saying this, a price increase of ETH is very often correlated with an increase in the activity on the Ethereum network — something that indeed increases the cost of transactions.
Now, let’s see how exactly an increase in network activity causes the transaction cost to go up.
To start with — all transactions sent to the Ethereum network land in the mempool. This is a place where all pending transactions are waiting for the miners to pick them up and include them in the next Ethereum block.
Miners are incentivised to pick up transactions with the highest gas price first as they are basically doing a fixed unit of work for a better price.
Miners are also limited to how many transactions they can include in one single block. This is determined by the maximum gas limit per block. At the time of writing this article, this limit is set to 12.5M gas.
As a quick example, let’s assume there are only simple ETH transactions in the mempool each one costing 21,000 gas. A miner can include ~595 such transactions (12.5M/21K). If there are, let’s say, 1,000 pending transactions in the mempool, the miner would choose transactions by sorting all pending transactions by the gas price and choosing 595 most profitable ones.
The current fee model is based on a simple auction mechanism and the users who want to have their transaction picked up by miners first have to essentially outbid other people for the space in a block. This in turn drives the gas prices up, especially at times when a lot of users have urgent transactions that they want to confirm.
Why Do We Need Gas
To wrap up the gas explanation, it’s also important to understand why gas has to exist in the first place. EVM as a Turing-complete machine allows for executing any arbitrary code. Although this is one of the main reasons that makes Ethereum so powerful it also makes it vulnerable to the halting problem. The halting problem is the problem of determining, from a description of an arbitrary computer program and an input, whether the program will finish running, or continue to run forever.
Without gas, a user could execute a program that never stops, either by making a mistake in their code or just by being malicious. To prevent this, Ethereum introduced a gas cost associated with each operation that would prevent a program from running forever and bringing the whole network to a grinding halt.
Besides the gas price, each transaction also has a gas limit that has to be equal or higher to the anticipated amount of computation needed for successfully executing a particular transaction.
EVM, before executing each operation within a transaction, checks if there is enough gas left for that operation. In case there is not enough gas left, the whole transaction is reverted with “out of gas” exception and all state changes are rolled back. The user would still pay the transaction fee for the amount of work that has been done by the miner even if the transaction fails. This is again to avoid attacks on the network.
If the transaction consumes less gas than initially anticipated the remaining amount of gas is converted to ETH and refunded to the sender.
It’s also really important that all operations on Ethereum have the correct gas cost in relation to each other; otherwise, that could be another attack vector. One of such attacks took place in 2016 and resulted in a hard fork that repriced certain low-level operations.
Now, as we know a bit more about gas, let’s have a look at the recent period of high transaction fees and a few solutions that can lower the transaction cost now and in the future.
High Fees on Ethereum
With record volumes on decentralised exchanges, the highest total value locked on defi lending platforms, multiple yield farming opportunities available, and minting more and more NFTs — the Ethereum network is as busy as ever.
This popularity results in high demand for block space which in turn results in high transaction cost.
It’s not uncommon anymore to pay more than $10 for a simple ERC20 transfer or $50–100 for a Uniswap transaction. This, of course, is not ideal as it makes it really hard for smaller players to participate in the Ethereum ecosystem.
Fortunately, there are multiple solutions either already available or being actively worked on. Let’s go through some of the most important ones.
Layer 2 Scaling and Eth2
Layer 2 scaling is a collective term for solutions that help with increasing the capabilities of the main Ethereum chain — Layer 1 — by handling transactions off-chain. Besides improving transaction speed and transaction throughput, layer 2 solutions can greatly reduce the transaction fees.
Loopring is a good example of a decentralized exchange built on Layer 2 that is getting more and more popular. The exchange has recently hit $200M in total value locked and over $10M in daily trading volume.
Another project — Matic — that was recently rebranded to Polygon also hit over $200M in TVL on their Plasma+POS chain.
A more general-purpose solution — Optimism — that is based on optimistic rollups is also being rolled out. This is important as it will allow DeFi smart contracts to interact with each other in a similar way to how they interact on Layer 1.
One of the missing pieces that can increase the adoption of Layer 2 solutions even further is direct onboarding to Layer 2. This could decrease the cost of transactions even further as users would be able to transfer their ETH directly from an exchange to a Layer 2 solution like Loopring.
If you want to learn more about Layer 2 Scaling check out this article here.
Besides Layer 2 scaling, another solution that can decrease the transaction cost, in the long run, is Eth2 which introduces sharding and Proof-Of-Stake. You can learn more about these concepts here.
EIP-1559 is another solution for optimising the transaction cost.
Although the proposal will not have a direct effect on lowering the transaction cost, it will allow for optimising the fee model by smoothing fee spikes and limiting the number of overpaid transactions. This will make transaction fees more predictable.
From the timeline perspective, it looks like EIP 1559 could be implemented in early 2021.
Here is a separate article that explains EIP-1559 in depth.
Optimising Gas Usage
Besides using Layer 2 scaling solutions and waiting for other improvements, there are a few other tricks that can help us with lowering our transaction cost on Layer 1.
First of all, if we don’t have any urgent transactions, we can try to find times of the day when the gas prices are the lowest.
Besides this, we should always double-check the gas cost estimated by our wallet with a separate reliable source such as https://ethgasstation.info/.
Another trick, used by 1Inch exchange, allows for lowering transaction fees with CHI tokens. These tokens must be burned alongside the primary operation, which allows for reducing the total amount of gas spent in a transaction.
This can be achieved by leveraging an EVM mechanism that refunds gas when storage space is freed. When CHI tokens are minted, dummy smart contracts on the Ethereum network are created. Burning CHI destroys these contracts and results in a gas refund.
So how about other chains besides Ethereum?
There is no doubt that the recent period of high transaction fees on Ethereum resulted in a few other chains capturing a meaningful amount of users and volume.
At this point, it’s hard to say how much of this will be a short-term play versus a longer-term user acquisition.
Saying this, we have to keep in mind that some of these chains are not fully decentralized and permissionless. This basically creates a fake DeFi ecosystem that may be fun to play with but is actually not that much different from using a centralized exchange.
So what do you think about gas and high transaction fees? What is your favourite way of lowering it?
Originally published at https://finematics.com on February 20, 2021.