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).
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.
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:
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.
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.
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.
As you will see in the table there are basically 3 types of gas limits:
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.
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.
On December 1, 2020 Ethereum 2.0 is born, which is characterized by replacing the Proof of Work algorithm with Proof of Stake. This means that there will no longer be miners consuming energy but transaction validators who will get a return for simply blocking an amount of ETH and keeping it over time.