Ethereum and its applications have seen a historic increase in network traffic as of late, and as a result, network fees have predictably climbed to all time highs. In this post I’ll talk about fees, “Gas”, how we calculate ETH fees, and the significance of Gas.
Introduction to Fees and “Gas”
Sending Ether or other Ethereum based assets requires the sender to include something called “Gas”. Gas, in Ethereum, is the metric used to calculate how much ETH you’ll pay the miners to mine your transaction or program (smart contract). Like in Bitcoin, users of the network must pay to use the network’s resources and operators of the network have to be incentivized with some type of reward.
In Ethereum, “Gas” is a computational unit or a measure of the number of resources needed to execute a smart contract on the Ethereum Virtual Machine (EVM). Some smart contracts require the EVM to use more resources to execute than others. Because of this variation, some transactions and programs need to pay more or less in fees than others. The less resources (computation, storage) your program requires to execute, the less ETH you’ll need to pay the miners.
The relationship between Ether and Gas is in a way, similar to the relationship between a fiat currency and gasoline, in so far as gasoline in meatspace is measured in gallons and paid for in a fiat currency like the USD or EUR. In meatspace, a gallon is the measurement, gasoline is the good desired, and a fiat currency would be the medium of exchange. In Ethereum, computation and storage would be the good desired, Gas is the measurement, and ETH is the medium of exchange.
Ultimately, Gas in Ethereum acts as a measurement that manages important ratios between the costs and availability of resources like computation, memory, and storage that the EVM provides. These are limited resources that need to be accounted and paid for.
Gas Price and Gas Limit
There are two components to Gas: the price and the limit.
The gas price communicates to the network what you’re willing to pay per unit of gas consumed. By toggling this price up or down you can increase or decrease your priority in the que. The more you’re willing to pay per unit of gas the higher priority your transaction will be for miners. If you’re being cheap and pay low gas prices compared to the rest of the network, you’ll be in the back of the que and might be there for a while.
The other key component to Gas is the “gas limit”. The limit is the highest amount of gas that the sender wishes to pay for their operation. This effectively puts a cap on the life of the program. It cannot run indefinitely as the program will have reached its gas limit at some point. To reactivate the program, more Gas will need to be purchased with more ETH. You will need to “refuel” so to speak.
To initiate any operation in ETH, the sender has to show the gas limit before sending it to the platform. Broadcasting your gas limit is like telling the attendant at the gasoline pump how much you’re willing to pay in total, while telling him your gas price is communicating what you’re willing to pay per gallon at the pump. When the “Gas limit” is multiplied by the “Gas Price”, the result is the maximum transaction fee the sender is willing to pay in ETH.
How does Edge Calculate Gas?
Edge uses ethgasstation’s API for the current level of gas prices, and we use Infura as well as Alchemy nodes for gas limit estimates. This combination allows us to accurately price an Ethereum based transaction for our users.
After getting gas price information from ethgasstation, we use this information to determine gas price estimates based on our priority levels: low fee, standard low fee, standard high fee, high fee, and custom fee which are freely chosen by the user. The standard fee is the default option.
Edge pings an Infura and/or Alchemy node with two calls:
(1) the “eth_getcode” call to determine the contract complexity of the recipient address
(2) the “eth_estimategas” call to get an approximate gas limit number based on the complexity of the recipient’s address.
We use “eth_getcode” to see if the user is sending to a contract (if eth_getcode returns a number greater than 0 it’s a contract, otherwise it’s a regular address).
- If a recipient address is not a contract, we use the standard 21000 gas limit.
- If a recipient address is a contract, we use the eth_estimategas RPC call to get a gas limit and we use that estimate as the gas limit.
Token transfers (ERC-20):
- We always use eth_estimategas to determine gas limit and we double the result for tokens due to potential inaccuracy with this number in internal testing. We do this to make sure the gas limit is high enough to ensure the transaction gets mined.
Gas’s Significance (Halting Problem)
Before Ethereum, most crypto networks were extremely similar to Bitcoin in their goals and architectures, with some slight modifications. Ethereum was one of the first crypto networks that had much broader capabilities and very different goals. Bitcoin and other assets like it are designed to work as electronic money. They’re technically programmable, but this programmability is extremely limited.
Satoshi limited Bitcoin’s capabilities on purpose. If Bitcoin had a more complete programming language, often called being a “Turing Complete” programming language, there would be no way to know when a program on the network would terminate without actually running the program on the network. This inability to predict when a program would end was proven mathematically by Computer Scientist & Mathematician Alan Turing in the 1940s. This is called the Halting Problem.
It’s somewhat trivial for many developers to create programs that could run indefinitely. The program would never stop and if enough of these infinite contracts were created, the entire network’s resources would eventually be taken up by infinitely looping programs (smart contracts). So instead of trying to solve an impossible problem, Satoshi sidestepped the problem by making sure the programming language of Bitcoin (Script) was limited but sufficient enough for an electronic money to function. Satoshi was busy solving the double spend problem with Proof of Work.
Ethereum didn’t solve the Halting problem outright, but it did address the problem. The Ethereum founders wanted to create a blockchain that had a more capable programming language which gave developers and users more capabilities on the network beyond sending, receiving, and creating different multi-signature schemes.
Gas, and the gas limit in particular, help address the Halting problem by creating a limit at which the program is terminated. Instead of trying to predict when a program ends, the architects of Ethereum created a metering system called Gas that shuts off the ability of looping programs to consume all of the Ethereum network’s resources indefinitely into the future, effectively cannibalizing itself.
Ethereum, like Bitcoin, is facing high fees because demand for blockspace on the network is historically very high. Much of this recent upsurge in gas prices can be attributed to the increased usage of the many financial applications that are being built on Ethereum. This is a signal that demand for these protocols and Ethereum needs to scale as quickly and as responsibly as possible to accommodate more usage.
Luckily Ethereum developers have been hard at work with different scaling solutions since the network’s inception. In a previous post we talk about Ethereum 2.0 and how the next version of Ethereum will be able to handle an incredible increase in the amount of raw throughput.
Gas is an intricate metering system designed to prevent naive or bad actors from creating resource hogging programs that loop indefinitely. This limitation or mitigation of infinite looping allows Ethereum to have a Turing complete programming language which has the effect of increasing the space of possibilities for other developers and entrepreneurs to build on top of.
Ethereum has come a long way since its launch and we look forward to its continued development. Much has been accomplished, but there is still a lot more work to be done.Download Edge on iOS Download Edge from the Play Store Android APK Direct Download