What is Ethereum Gas?

- Cryptocurrency, Ethereum

Ethereum Gas explained

Perhaps you’ve already faced the situation when an Ethereum app doesn’t want to run, because you have no gas. But what does this term mean? Is it possible to use the application without Ethereum gas? Where to charge the app? And where to get the Ethereum gas price chart? We provide answers to these questions below.

First of all, read this small but informative description:

  • In Ethereum gas plays a role of the execution fee.
  • Ethereum gas is used to run every operation within the ecosystem, so it is impossible to run Ethereum apps without gas.
  • The Ethereum gas price is expressed in ether and decided by miners, so there is no fixed gas price that transactions must have.
  • If an Ethereum miner decides that a transaction has to low gas price, her or she can refuse the transaction.
  • If you are wondering where to take Ethereum gas, simply add ether to your account. Thus, you will make your Ethereum application run.

Now, let’s try to figure out the relation between EVM, dApps, and blockchain. EVM is the abbreviation of the Ethereum Virtual Machine – an execution environment implemented on the blockchain. As for dApps, they represent an absolutely new kind of applications – decentralized apps. These apps require Ethereum gas to work. When such application is run, the following happens: there is a network with nodes and every instruction is executed on these nodes. Since the operations are not free, you should spend a specific amount of gas units on them. The more complex the transaction is, the more gas it require. You can see a cost of every operation that a script can execute in the EVM specification.

Ethereum cryptocurrency blockchain

The same is about the Ethereum gas price chart, you can find it in the EVM specification, but it isn’t something constant, because miners may decide how much a unit of gas costs. Now, it is around 50 GWei. Another unknown value? GWei is 10^-9 ether which is used as an internal currency or token for the ecosystem (but there is one important aspect described below). Thus, all your account holdings are by default expressed in ether, but you can recalculate them in GWei. Don’t forget the aforementioned ratio, and you won’t need an Ethereum gas calculator to figure out the amount of ether you will earn or spend. As for a more complex, explanation, it is provided on Ethereum StackExchange by Jeff Coleman. Here is how he describes the meaning of Ethereum gas for the whole ecosystem.

As we already know, the term “Gas” is used to describe a special Ethereum unit designed to measure the amount of work necessary to perform a certain action or a set of actions. Jeff provides a very eloquent example. He talks about calculating Keccak256 cryptographic hash. For each hash calculation, it is necessary to spend 30 units of gas. Furthermore, every 256 bits of hashed data also cost 6 more gas units. And the same principle is applied to every Ethereum operation performed by a transaction or contract: a certain number of gas is consumed. Thus, it isn’t hard to guess that the more computational resources the operation utilizes, the more gas it requires. And operations that require few computational resources cost less. But why is Ethereum gas important?

The reason is obvious: it helps to ensure an appropriate fee is being paid. So all transactions submitted to the network are run fairly. At the same time, the Ethereum ecosystem allows to eliminate all unnecessary transactions. The necessity to pay a fee for each performed operation ensures that the network doesn’t become overwhelmed with intensive and at the same time useless work. Do you remember how things are done in case of Bitcoin? In this ecosystem the only thing that matters is the transaction size, so the network became bogged down with redundant work. What are other consequences of this revolutionary new approach to currency or token?

The code length is reduced and at the same time leads to the bump in effectiveness, since more computational work can be done. This is also possible because Ethereum allows arbitrarily complex computer code to be run. As a result, the directly done work matters in contrary to systems where a fee is based on the length of a transaction. This makes interactions between customers and developers much more fair.

Do you remember that we’ve mentioned that one more aspect related to tokens should be described? Ethereum gas has one a little bit complicated nuance. Being basically a transaction fee, gas doesn’t have any actual token. You can freely use it to measure things in the ecosystem, but you can’t own 357 units gas. How does everything work?

Gas exists inside the Ethereum Virtual Machine in a form of a count. Its role is to calculate how much work is being performed. And while paying for the gas, a certain number of ether is charged as a transaction fee.  So the ether is the built-in token used to reward miners within the system, not the gas.

The differentiation is caused by the Ethereum price. Like bitcoin’s price, it doesn’t have a constant value and can be changed rapidly and varies a lot depending on market conditions. Therefore, Ethereum gas is used to make the price of computation independent from the price of the ether token and its constant fluctuations. Every time the market moves, the the price of computation remains the same.

Now, we should dig into that even more and describe two very important parameters of every operation: gas cost and gas price. All transactions specify the gas price (in ether) they are willing to pay for each gas unit. As a result, the market decides the relationship between the ether price and the computing operations cost measured in gas. The total fee paid by a transaction can be calculated in the following way: the total gas used is multiplied by the gas price. To make the meaning of these two parameters more clear, imagine that a gas price is a miner’s hourly wage, and a gas cost is a timesheet of performed work.

Due to this approach there is a huge difference between a situation when a transaction runs out of gas and when it doesn’t have a high enough fee. Let’s describe the second one, since it is more simple. When the gas price is too low, no one will run the transaction in the first place and it won’t be included in the blockchain. You don’t want  to work for free or for a knock-down salary, so why should someone else do this?

As for the first case – a transaction runs out of gas – this usually happens when an acceptable gas price is provided, but a transaction results in lots of computational work, so the amount attached as a fee is overbalanced by the combined gas costs. In this situation, the gas is counted as “spent” and you don’t get it back. At the same time the miner stops transaction processing and reverts changes. Next, the transaction is included it in the blockchain as “failed”, but  fees for it are collected.

Thus, miners are always paid for the work they do. If your transaction runs out of gas, and the miner didn’t complete it, this is completely your fault. Such approach may seem harsh, but it is totally fair, because you always pay for the performed work.

Now, let’s consider the situation with a too big fee. Being too generous isn’t a good idea at all. A very high Ethereum gas price leads to high expenditures: you have to spend a lot of ether for just several operations. In comparison to the Bitcoin ecosystem, it is the same to a super high transaction fee. Your task gets higher priority, but it consumes too much resources.

And here is the last Ethereum gas use case example we’d like to draw your attention to. The gas price provided for the transaction is quite normal, but the amount of the attached ether is more that the transaction consumes. Don’t be afraid:  the left amount will be always transferred back to you. Miners never get more than they deserve.

Of course, there are lots of other use cases for Ethereum gas, but these are the basic ones. Other cases are just their variations, so we don’t want to waste your time by describing them all. As for Ethereum gas itself,  it is the key metric and the the core mechanism responsible for the safety of the network and its complex computations.  Any program that runs out of control stops right when there is no more money. When the budget is empty, no one will work on the application.

Furthermore, mistakes you’ve made in a program affects only the limited amount of people. To be more exact, only the people who pay to use it. Thus, the rest of the network remains stable and indifferent to performance issues caused by your errors. And this is the basic idea behind the blockchain technology. Without it, a general-purpose blockchain and better Internet would be impossible.

Conclusion

Let’s figure out all key aspects related to Ethereum gas to summarize this post. Now, you know that gas is the source of life for the whole Ethereum network and the only way fees are calculated, but they are still paid in ether, which is different from gas.

The gas cost represents the amount of work, while the gas price acts as the hourly wage. You know how to combine them to calculate the total transaction fee. Transactions with too low gas price are never processed. Transactions with normal gas price but costs that run over the budget fail but still go to the blockchain – you don’t get your money back, but the miner gets paid for the performed work.

As a result, the Ethereum ecosystem allows to create conditions where people are careful about the code they run and create, so both developers and customers stay safe from bad code.