What is GAS in Ethereum?

Tiempo de lectura: 6 minutos

If you’ve made it this far, you’ve probably heard of ‘Ethereum Gas’ and that expression has struck you so much that you’ve decided to investigate its meaning. If you want to know what Gas in Ethereum is and what it’s for, read on.

Before explaining how gas works in Ethereum, it is important for you to know that the Ethereum network works in a similar way to Bitcoin.

In the Bitcoin protocol, transactions provide for a commission to be paid in satoshis (the smallest decimal unit of Bitcoin).

  1. These commissions serve as an incentive to pay for the tasks performed by the miners, who are the ones who keep the network running.
  2. In addition, putting a cost on any transaction ensures the security of the network, as it makes it unprofitable for a hacker to carry out attacks.

As you probably already know, Ethereum works on its own open source network, based on a blockchain and, as in the case of Bitcoin, the miners (or Master Nodes) that are part of the network, are responsible for processing and validating transactions. When validating a transaction and once each block in the chain has been successfully resolved, the miners earn a fee in the form of a reward.  

This is where the “gas” comes in, which can be considered, as the name suggests, the fuel that drives the applications and transactions executed on the Ethereum network.

So, to better understand the concept of gas in Ethereum, imagine a car that needs gasoline to run. In the same way the Ethereum blockchain needs fuel in order to function and process transactions.

How does Gas work in Ethereum?

You are probably now wondering how gas works in Ethereum and why the Ethereum protocol uses this system. Below I will explain it to you.

The Ethereum network runs as a computer or virtual machine called the Ethereum Virtual Machine (EVM) . Most smart contracts running on the EVM are coded using a programming language called Solidity. Each line of code in Solidity requires a certain amount of gas to be executed.

This means that all transactions that users execute on ethereum must provide gas for:

  • Cover your data (intrinsic gas).
  • Cover your entire calculation.

Like any proof-of-work system, Ethereum relies heavily on the hashrate of its miners. The more miners there are on the network, the more secure and faster the system will be.

So, to attract more miners to the system, it is necessary to use incentives. Miners can earn money by mining blocks and getting rewards in the form of gas. 

This means that, in order to perform an action on Ethereum, a user has to pay a small fee corresponding to the amount of Gas used in order to perform that action on the blockchain.

What is the Gas Price

The gas rates (or price) are called “gwei”, a denomination of Ethereum’s native currency, ether (ETH). 1 gwei, also known as nanoether, is equal to 0.000000001 ETH.

Gwei are payments users make to miners to compensate for the computing power required to process and validate transactions on the Ethereum blockchain.

So what does the price of Gas in Ethereum depend on? 

Well, the Ethereum network can only process a limited number of Gas units at any given time as otherwise the network could be overloaded by heavy usage. For this reason, Miners are in charge of controlling the number of requests that are sent and, at the same time, decide which transaction to give priority to.

How do they do it? By taking into account the Gas Price and the Gas Limit.

In other words, if you want the miners to give priority to your transaction, you will have to pay more Gas. The higher the price you are willing to pay for each unit of Gas, the faster the miners will process your transaction.

One of the advantages of this system is that it separates the cost of the transaction from the cost of ETH, thus preventing transactions from being too expensive.

In fact, Ethereum developers decided to assign constant values to the different operations that users can perform on Ethereum so that each task on Ethereum has a predefined Gas value,which means that it does not change according to the rise or fall in the value of ether.

So, although the price of ether is volatile, the cost of operations always remains constant. 

What is the gas limit in Ethereum?

límite de gas en ethereum Bitnovo

When we talk about gas in ethereum, we also usually talk about the “Gas Limit”.

As I explained earlier, the Ethereum network relies on a system based on the Proof of Work (PoW) algorithm, and miners working on the network use special hardware to process Ethereum blocks full of transactions. In exchange for their service, miners earn rewards through gas payments.

Different types of activities on Ethereum have different gas costs, which increase according to the complexity of the activity on the blockchain.

So, the gas limit refers to the maximum amount of gas you are willing to pay when performing a transaction on the Ethereum blockchain. The higher the gas limit, the more you have to work to execute a transaction on the Ethereum network.

The system works like this:

If you want to perform an operation on Ethereum (be it a transaction or a Smart Contract), you must specify a gas limit before sending it to the network. The gas limit is the maximum amount of gas you are willing to pay for this transaction.

Normally the gas limit is always greater than the actual amount of gas required for the transaction. 

In fact, if you specify a gas limit that is too low (i.e. operations require more gas than you have allocated to the transaction), then a miner will complete the transaction until the gas runs out. If this happens, the transaction will fail and the miner will keep the commissions (taking into account the expense you incurred in terms of time and energy in executing so many transactions). This transaction will be recorded in the blockchain as “failed”.

Here is a table from the Ethereum Yellow Paper that indicates approximately the cost of a specific instruction in gas.

ethereum yellow paper Bitnovo

As you will see in the table there are basically 3 types of gas limits:

  • The Gas Limit of a transaction is 21,000 gas. This means that a basic transaction cannot consume more than this amount of gas.
  • The Gas Limit of a Smart Contract is higher and can vary between 130 and 145 thousand Gas Units, depending on its level of complexity.
  • The Gas Limit of a block cannot exceed 8 million Gas Units. This means that miners can include as many transactions and shares as long as it does not exceed this limit.

How to calculate Ethereum transaction fees

There are several useful resources to help you calculate the gas prices and fees needed to execute a transaction on Ethereum.

Because of this, when executing a transaction on Ethereum, I recommend that you use a gas calculator available on various platforms.

These calculators give you an estimate of the amount of gas your transaction requires.

  • Ethereum Gas Station is one of the most popular and widely used platforms for estimating the right gas price, as it has an easy to use interface and for its accuracy.
  • Another platform I advise you to use is GasNow. This platform is based on SparkPool’s pending transaction queue (which covers all transactions in the main network) and calculates commissions based on the pending transactions it has to process in the network.
  • EtherFees is nothing more than a Twitter bot that displays the speed, average, low insurance and gas price number needed to confirm your transaction.
  • EtherScan provides information on gas prices and transaction confirmation times. Estegas tracker also displays the histogram of the time spent in the transaction pool and the gas price for the last 1000 blocks.
  • Ethviewer is an interactive transaction viewer that displays the number of transactions, gas prices paid and the amount of ETH in the pool, sorts transactions by gas prices paid and displays each transaction on the Ethereum blockchain live.

If you don’t want to use such tools, you can always calculate your own transaction fees by multiplying the current gas price by the current Ethereum gas limit :

Gas price * Gas cap = Transaction cost

As you have seen, Gas in Ethereum is the lifeblood, the fuel of the Ethereum ecosystem and is, without a doubt, a tremendously important innovation in the blockchain community, since it contributes to creating a fairer and more transparent space in proof-of-work blockchain-based mining.

Leave a comment
Your email address will not be published. Required fields are marked *