Ethereum Transactions: What is Gas and what is it used for
When someone starts trading with Ethereum, it is normal to ask: What is Gas used for in Ethereum? Understanding the mechanics of gas and its associated concepts, such as gas limit or gas price, is crucial for executing transactions on the Ethereum blockchain.
Before diving into the details of gas, it is necessary to have a basic understanding of Ethereum. Although we will introduce you to this cryptocurrency to give you an overview, we recommend reading the article about Ethereum to understand all the terms.
Table of Contents - Explanation to understand Gas in Ethereum
- Principles of Ethereum
- What is Gas in Ethereum
- What is Gas used for
- Ethereum Transactions
- TxHash or Transaction Hash
- TxReceipt Status or Transaction Status
- Block Height or Block Height
- TimeStamp or Time Stamp
- From / To or Sender / Recipient
- Value or Transfer Value
- Gas Limit or Gas Limit
- Gas Used By Transaction or Gas Used by Transaction
- Value or Transfer Value
- Gas Price or Gas Price
- Actual Tx Cost/Fee or Transaction Cost
- Nonce & {Position} or Nonce and Position
- Input Data or Input Data
- How to pay less in an Ethereum transaction
- How to speed up an Ethereum transaction
Principles of Ethereum
Ethereum functions as a large computer where all Ethereum operations are executed. This mega machine is known as the Ethereum Virtual Machine or EVM.
But the reality is that what we call a large computer is not a central server, but rather it is composed of thousands of individual computers connected to each other via the internet.
Each of these computers is known as a node. The nodes that contribute their computational power to execute transfers, Ðapps or smart contracts are known as miners.
As you can understand, maintaining these computers is not free. The machines wear out over time, require an internet connection, and consume (a lot of) energy.
Therefore, to reward miners who contribute their computers, the concept of Gas was introduced in Ethereum.
What is Ethereum Gas
Gas is the unit of measurement of computational work to execute any operation on the Ethereum network. These operations can be transactions, smart contracts, or Ðapps.
To make a comparison, it can be likened to the electrical consumption in kW of a computer. In the case of the Ethereum platform, this consumption is measured in Gas.
It is important to understand that the consumption of Gas is not always the same and varies depending on the operation to be performed. Just as a light bulb consumes differently from a television, a complex smart contract requires more Gas than a simple transaction.
Why is Gas necessary?
If the Ethereum platform uses ether as its currency, why doesn't it use cryptocurrency as a reward?
The answer lies in the fact that ether, in addition to being used on the Ethereum Blockchain, is a financial asset. This causes its price to constantly fluctuate, even more so with the volatility that the cryptocurrency market presents.
On the other hand, the computational cost is much more constant, as the cost of computer components or electricity is not as volatile.
To help you understand this better, we want to show you an example.
Imagine that a fixed transaction fee of 0.1 ETH per operation is established.
When the value of ether was €10, this cost would amount to €1. However, when it was at €1,000, this hypothetical cost would be €100.
Who would be willing to pay €100 for a transfer? That's why Gas was created.
The cost of Gas remains relatively constant according to the computational cost and certain parameters of the Ethereum protocol. This manages to separate the financial value from the cost of transactions.
In short, the function of Gas is to establish a computational cost and separate it from the value of Ethereum. This cost will be charged in each of the operations on the platform and will be delivered to the miners.
Ethereum Transaction
To make it clearer, we are going to teach you all the concepts of an Ethereum transaction, which we will explain one by one. Transactions on the Ethereum platform are public and can be consulted in real time on etherscan.io.
For example, the transaction we used in the example can be consulted here.
The term Tx is a diminutive of Transaction.
TxHash or Transaction Hash
Every transaction made in Ethereum has an identifier called Hash. It is represented by an alphanumeric code like the following:
0x3b922e816830ad18d7a84a95004ac33ea9c31fd590d09d9051a651e0e5f20045
This code encrypts transaction information and works similarly to the hash used by bitcoin. It is crucial to the functioning of the blockchain and plays a role in the work of miners.
TxReceipt Status or transaction status
TxReceipt Status refers to the status of your transaction.
If you make a transaction and immediately check it on etherscan, it will likely show as Pending.
Once it is confirmed, you will see the message Success. If something goes wrong, it will show as Fail or Reverted.
Block Height or altura de bloque
The Block Height is the number of blocks that precede the block where the transaction has been processed.
For example, the Genesis Block or Block 0 has a block height of zero.
In parentheses, it usually indicates the number of confirmations that have been required to process the block.
The Genesis Block or Block 0 is the first block of a blockchain or Blockchain chain
TimeStamp or time stamp
The time stamp is the moment when the operation was performed. It is the exact moment when you press the button to make an Ethereum transfer.
From / To or Sender / Recipient
The following two fields are the alphanumeric codes that identify the sender (From) and recipient (To) wallet.
In the example case, the recipient is a smart contract. Therefore, the word Contract appears next to the code.
Value or valor de la transferencia
The field Value collects the total transfer amount in Ethereum
In the case that the operation is to execute a smart contract, as is the case, the amount will be 0. The user will only have to pay the Gas.
Gas Limit or Gas Limit
The Gas Limit is the maximum amount of Gas that will be paid to successfully perform a transaction.
Usually, this data is automatically calculated at the time of the transaction to pay as little as possible. However, there are some platforms that allow the user to input it manually.
A simple transaction requires a Gas Limit of 21,000 units.
For contracts, this data depends on their complexity. The more complex it is, the more computational expense it will require, so more Gas will need to be spent.
The Gas Limit is actually a protection for the user. Imagine you execute a contract with a programming error that causes it to repeat infinitely. This would consume all the ether you have.
The Gas Limit prevents this type of human errors.
In the example, the user has set a Gas Limit of 200,000 units, but did not need to spend it all, as we will see next.
Gas Used By Transaction or Gas Used by Transaction
The Gas Used is the Gas that the transaction has needed to execute.
Usually, less Gas is consumed than the one set by the limit. That is the case of the example, which has used 94,659 units, 47.33%. What is certain is that it will never exceed the value set by the Gas Limit.
Out of Gas or Out of Gas
When a transaction is performed, miners will start executing it. If the Gas set by the limit runs out before it is fully executed, miners will stop working.
In these cases, the Blockchain will throw a failure (Fail). Additionally, you will lose the ether intended for Gas, as payment for the miners' work.
These situations are known as Out of Gas or Out of Gas.
Gas Price or Precio del Gas
The Gas Price is the price you are willing to pay for each unit of Gas.
The price of Gas is variable and depends on how congested the Ethereum Blockchain is. The more work the miners have, the higher the Gas Price needed for a transaction.
For example, to speed up the execution of an Ethereum transfer, you can set a high Gas price. This way, your transaction will be prioritized by the miners, as they will receive a higher reward.
The Gas Price is usually measured in GigaWei (Gwei). One Ether is equivalent to 0.000000001 Gwei.
Actual Tx Cost/Fee or Transaction Cost
The Actual Tx Cost is the total cost of the transaction or commission (fee).
It is very simple to calculate. Just multiply the Gas price by the Gas units consumed.
Nonce & {Position} or Nonce and Position
In Ethereum, there are two types of nonces:
- The nonce of an account. It is an index that represents the number of transactions made by an Ethereum wallet. The first value of the index is 0. Its function is to prevent double spending.
- The Proof of Work nonce. It is the random hash that miners have to find to process a block. We explain it in detail in the article about Blockchain.
Logically, transactions refer to the nonce of an account.
The position is the number of the transaction within the block in which it has been executed.
Input Data or Introduces Data
The field Input Data is a message sent to the receiving account or an initialization code if it is a contract.
If the sender does not enter any message, usually the code 0x appears.
How to pay less in an Ethereum transfer
It's normal to get confused with so many terms. You may be wondering what you need to do if you want to transfer ETH.
Don't worry, as we mentioned before, Gas is automatically calculated on the most widespread platforms.
If, however, you are using a platform that asks you to set these data, the best option is to consult ethgasstation.info.
On this website, you will find current data about the price of Gas. The most advisable thing is to pay attention to the box Recommended Gas Prices that shows three concepts:
- The SafeLow, which is the price of the gas that Ethereum users are currently paying for a transaction with low priority.
- The Standard price, which is what you pay for a transaction with normal priority.
- The Fast or quick price, which is the price paid for a transfer with high priority.
In addition, in quotation marks, you will find the estimated time for each of the prices. In the image, less than 2 minutes for Price Gas Fast; less than 5 for Standard; and less than 30 minutes for a SafeLow transaction.
Remember that the standard Gas Limit for a simple Ether transaction is 21,000 units.
How to Speed Up an Ethereum Transfer
If you are someone impatient and prioritize transaction speed over saving some ETH, forget about SafeLow.
Instead, use the price indicated as Fast on ethgasstation.info.
Found it interesting? Learn much more about Ethereum in our cryptocurrency guide.