Learn what Gas is, a unit of measurement used to measure the work done by Ethereum to carry out transactions or any interaction within the network.
Unot one of the most important concepts in the world of Ethereum is the Gas. A word that many have surely seen in their transactions on Ethereum or the interaction of Smart Contracts and surely you have wondered What is Gas? Well, to quickly answer that question, from Bit2Me Academy we can define it as follows:
Gas in Ethereum is a unit of measurement used to measure the work done by Ethereum to carry out transactions or any interaction within the network.
Yes, that simple, is the concept of Gas. But do not be fooled, this simple concept hides much more behind it, and that is that Gas is essential for everything within Ethereum, and its impact on this ecosystem is immense.
That is why taking into account the importance of this concept, we have created a small guide that will help you understand everything you need to know about Gas and its role within the blockchain Ethereum.
An analogy to understand what is Gas in Ethereum
A simple way to see what is the Gas in Ethereum would be the following analogy:
You want to travel with your family from Madrid to Barcelona, the trip will be done in your car. At this point, you know in advance that it is 500 km away and that your car uses 1 liter of gasoline every 10 km (to make the calculation simple), so you will need 50 liters of gasoline to reach your destination. In addition, you also know that a liter of gasoline costs between € 1 and € 1,5 depending on the gas station where you stop to refuel.
This is the same thing that happens in Ethereum. On the one hand, each task in Ethereum has a specific and non-variable cost stipulated in Gas, which is equivalent to the liter of gasoline your car uses per 10 km. Of course, operations in Ethereum are made up of different smaller functions , each one with a specific Gas value (or gasoline consumption) and their sum is what will tell us the final Gas value of said operation (the total gasoline to be spent to make our trip). So we only have one thing left, how much will we pay for that Gas to be able to carry out the operation in Ethereum?
In our analogy, gasoline varies between € 1 and € 1,5, you can choose where to refuel and pay as little as possible to buy the 50 liters of gasoline you need for your trip. The same happens in Ethereum, Gas has a price in Ether that is given by the demand and supply of operations in Ethereum. That is, the price of Gas in ether is variable, although in this case you can choose the value that you are going to pay for that Gas, and if a miner agrees with that value, they will take your transaction and execute it.
As you can see, the concept of Gas is something very powerful and useful within Ethereum, and we will examine further why this great relationship.
Gas, a unique way to measure computing power in Ethereum
The blockchain or chain of blocks that use the protocol Proof of Work (PoW), they all work under the same premise:
In order for you to make a transaction that is accepted and included in the blockchain, a commission has to be paid for the miners to take your transaction and include it in a block. Once there, said transaction will be validated by the network, and then, the orders that are in the transaction will be executed, only then will you be able to say that it has been accepted and confirmed.
A simple way to see PoW, but it is a correct idea. This means that to gain access to a blockchain network we must always pay a small price. Generally this payment is made in decimal units of the currency that works on the blockchain.
This would be the case with Bitcoin, where transactions are paid in satoshis, the smallest decimal unit of Bitcoin. The objective of this is simple and we will summarize it in the following list:
- Assign a cost to any task that runs on the network. This maintains the incentives to run the network, a task that depends on the miners.
- Maintains system security by preventing indiscriminate access to resources. Because everything has a cost, a hacker for example, could not dedicate himself to sending spam or performing a DDoS over the network, because it would be excessively expensive.
If this applies to Bitcoin, ask yourself, won't the same apply to Ethereum? The answer is yes, the same thing happens in Ethereum, only that its creators have sought a different approach to this problem. The decision to create this mechanism called "Gas", It responds to the fact that Ethereum is much more than just a cryptocurrency. In fact, the Ethereum network as a whole works in a similar way to a computer, a computer known as the «Blockchain Computer».
Why was Gas created?
Continuing with the above, you should know that in Ethereum each transaction is a "small program". This program instructs the Ethereum Virtual Machine (EVM), so that later this machine interprets them as an action or series of actions to be carried out. At this point, Ethereum and its EVM are equal in operation to Bitcoin and Bitcoin script. What really sets them apart is that Ethereum offers much greater flexibility than Bitcoin.
However, In Ethereum the developers decided to assign constant values to the different operations that can be performed in Ethereum. In this way, each task in Ethereum has a stipulated Gas value, which does not change and is not altered by the rise or fall in the value of Ether, Ethereum's native currency.
The fact that this Gas value is constant responds to the fact that, Although the price of ether is volatile, the computational cost of operations always remains constant. That is why, with the creation of Gas, Ethereum developers can then differentiate between what the computational cost and the real value of said operations at a given time. In fact, this system helps Ethereum and its network remain usable at all times, regardless of ether rises or falls.
For example, if a smart contract has a function to "Check balance of an address", this action in the network can have the value of 1000 Gas, and it will always have that value. This means that to carry out this action in Ethereum, a small commission (in ether) has to be paid corresponding to the amount of Gas used to be able to carry out said action on the blockchain.
The above generates three things that are important and vital within Ethereum, and which we explain below:
- Gas Unit. The Gas Unit is the amount of Gas that can be attributed to a specific instruction, but it has no monetary value.
- Gas Price. The Gas Price for its part is the commission payment we make for each Gas Unit. It is a price that we choose to pay for each unit and we do it using decimal units of Ether, called Gwei. This commission is what allows you to have priority of attention. If you pay more for each Gas Unit you use, the faster miners will take your transaction and take it to a block.
- Gas Limit. This is a value that indicates the maximum number of Gas Units that the Ethereum network can handle at any given time. It is their maximum limit, and it is a point that miners cannot exceed at any time.
As you can see, it is much more complex than what happens in Bitcoin or other derivative cryptocurrencies, and the reason for this is; that in Ethereum, the EVM is limited to handling a certain amount of information. So to handle that information limit, this work metric has been created to control the amount of computational work that the network can do at the same time.
Gas Curiosities in Ethereum
How much is the Gas limit?
The Gas Limit depends on whether we refer to a transaction, an operation with smart contracts or a block. Thus we have the following limits:
- The Gas Limit of a transaction is about 21.000 units of Gas. This means that no single transaction within Ethereum will ever consume more than this amount of Gas.
- For its part, the Gas Limit of a smart contract is much higher and is variable. This is because these smart contracts may have more or less complexity in their interactions and this adds a higher level of Gas. Normally this limit is usually between 130 and 145 thousand Gas Units.
- Finally we have the Gas Limit of a block, which is established not to exceed 8 million Gas Units. This means that miners can include as many transactions and interactions with smart contracts as possible, as long as they do not exceed that limit.
This last limit is interesting because it allows to face the "Halting problem". This is a computing problem that allows us to know if a computer program will run in an infinite loop just by having data entry and programming at hand. This situation would pose a serious problem on the blockchain that could lead to a Denial of Services (DoS). However, because Ethereum imposes a Gas Limit per block, this means that no operation on Ethereum, no matter how complex, can ever exceed this limit.
How do miners get paid for their work?
As we have already mentioned, Gas has no economic value, nor is it a token within Ethereum, it is only a unit of measurement. It is an important unit in order to establish the value of transactions. This is thanks to the fact that each Gas Unit is priced in Gwei (decimals of Ether). So, for a transaction that consumes a certain amount of Gas, you must pay a certain amount of ether in order for it to be processed.
For example, if we have an operation "Pay Maria" with a cost of 12.000 Gas Units, and the cost of the Gas Unit is 20 Gwei, we have to:
TX cost in Gwei = 12.000 * 20 = 240.000 Gwei
Cost TX in Ether = 240.000 Gwei * 0.00000001 = 0.0024 Ether ~ $ 0,54 / € 0,48
Now you know how commissions are charged within Ethereum. As you can see this also has an impact on the block reward. Currently, Ethereum's block reward is 2 Ether per block, which is mined every 15 seconds on average.
So each block generated has a fixed reward of 2 Ether. While the rest of the reward is given by the commissions charged by the miner following the example shown above. Of course, the gas value of the transactions is adapted to each case. Due to this, a simple transaction (consumes little Gas) is not the same as an advanced smart contract with several described actions (consumes a lot of Gas).
In fact, in the latter, the Gas and the amount they can use is determined by the complexity of the instructions they can use in the EVM. The Ethereum developers have a list of these instructions and their cost in Gas that you can review here.
Introductory course to DeFi
Medium levelTime to update. Traditional finance has changed, discover the revolutionary ecosystem of decentralized finance (DeFi).