Understanding gas, gas price and gas limit

5 117
Avatar for aniruddhasen
3 years ago

Eth is the most dynamic crypto ecosystem and all of us have transacted in this at some point of time. It is the god mother of numerous Dapps and has millions of dollars worth of transactions daily. It is important that transactions on this network are verified otherwise there will be total chaos and lack of faith in the eco system, leading to its collapse. We routinely use the term gas but we do not have a reasonable understanding of what it is. But everyone who is somewhat serious about crypto should have an outline idea about what gas is.

To verify these transactions we have the miners with immense computational power who do this work. This is where ‘Gas’ comes into play. Gas is the unit of work here. Let me explain it. Suppose a transaction is meant to add two numbers then it means 3 units of work. If the transaction involves multiplying two numbers then it amounts to 5 units of work. These guidelines are mentioned in the yellow paper. These units of work are called ‘gas’. So from this we know how many transactions are required in each case and the amount of gas it will require. But we still don’t know how much ETH has to be paid for that transaction. How to convert gas into ETH terms? Here gas price is required in ETH terms.

Before going further, let’s break down ETH into smaller denominations just as BTC is subdivided into satoshi.

1 ETH = 1000 Finny = 1 million Szabo = 1 billion Gwei = 1 quintillion Wei (smallest unit of ETH).

These names Finny, Gzabo, Shannon, Lovelace, Babbage, are not names thought of out of thin air but these are the names of persons who contributed a lot in the development of crypto currency. You can see the data below. For gas the term we use out of these is Gwei which is 1 billionth of 1 ETH.

So, 1 Gwei of gas is actually 0.000000001 ETH.

Gas price is how much you are actually willing (or you are actually required to pay) for per unit of work. In metamask you will see the option of gas price mentioned and it can be edited as per the speed at which you want your transaction to complete. The ethgasstation gives the current estimate of gas that is prevailing, and you can compare form this website to get an idea.

 I will give an example here. Suppose you want to buy a box of candy and you are willing to pay 5 cent per candy. Your budget to buy the candy box is 5 dollars. Another person comes and he is willing to pay 7 cents per candy and his budget is 8 dollars. Here the per unit price you are willing to pay is the gas price. When someone is willing to pay 7 cents for the candy, so he will get it before you. Likewise if someone is willing to pay 7 gwei (0.000000007 ETH) for a transaction for which you are willing to pay 5 gwei (0.000000005 ETH) so obviously the miner will process the transaction of 7 gwei first. For this reason you will find when markets are volatile the gas price increases as some people are willing to pay more so that their transaction is processed first or earlier. Miners will automatically make a list of transaction in descending order so the higher gas price orders are processed first.

Now comes the ‘gas limit’ which we seldom change while processing a transaction. As per the above example you are willing to pay a maximum of 5 dollars but the other person is willing to pay a total of 8 dollars. This total amount of gas you are willing to pay is the gas limit for that transaction. An example will make it clear.

Suppose you are willing to pay gas fees of 5 gwei and set a gas limit of 21000(which is the standard for transacting ETH). 5 gwei is 0.000000005 ETH multiplied by 21000 = 0.000105 ETH. Just as you were willing to spend 5 dollars to pay the candy box so you are willing to pay a maximum of 0.000105 ETH for the transaction. So gas price (gwei) multiplied by gas limit is the max you will pay. If while processing your transaction, the number of units of work is too many and your total gas falls short then your transaction will fail.

Suppose your transaction has 100000 units of computation and for each unit you are paying 5 gwei per unit then it will require 100000 x 5= 500000 gwei(500000 x 0.000000001= 0.0005 ETH), but as you have set the limit of 21000 (0.000105 ETH ) therefore your transaction will fail. You will run out of gas before the full computation is complete. You will need to increase gwei from 5 to a higher rate so that your transaction is complete. As a common person we don’t know how much total gas will be required so if we do not set a gas limit then the transaction may run into several hundred dollars to execute. To protect ourselves from this we set the gas limit. Below is a picture of a failed transaction as it went out of gas.

If less gas is required than what you have stipulated then the extra gas is returned to you. If transaction fails due to less gas then the fees are not refunded. Before making in Eth or ERC 20 transaction it is better to visit ethgasstation as see the prevailing rates. Generally ERC 2O transaction will have higher gas fees than ETH transactions. Also a simple sending of coin from one wallet to another will cost less. Sending or interacting with smart contracts and Dapps will cost more. Swapping or exchanging will also cost more. Its all based on the number of computations required to execute the transactions. It is generally said that weekend mornings are the best time to transact ETH or ERC20 tokens.

 

 

3
$ 12.47
$ 11.89 from @TheRandomRewarder
$ 0.53 from @Telesfor
$ 0.05 from @Jnavedan
Sponsors of aniruddhasen
empty
empty
empty
Avatar for aniruddhasen
3 years ago

Comments

Thank you Telesfor sir.

$ 0.00
3 years ago

And soon all this (gas and gas limit) will be available in the SmartBCH sidechain.

$ 0.00
3 years ago

But fees are so low already in BCH. Can you post some details about smartBCH sidechain.

$ 0.00
3 years ago

Test dApps you can find here:

https://ba.net

$ 0.00
3 years ago

https://docs.smartbch.org/smartbch/

It is not about transaction fees for money transactions. It is about smart contracts. Technically, it will work exactly like Ethereum. The SmartBCH addresses will also have the same form as ETH. You will be able to exchange BCH for SmartBCH 1:1. The SmartBCH Sidechain will enable the execution of smart contracts. The good thing is that the smart contracts created for Ethereum can also be executed in the SmartBCH sidechain. The advantage is that the smart contracts will be executed with very low gas fees (Ethereum network is already very expensive and therefore all contracts are expensive). It will also be possible to execute the tokens on the SmartBCH chain (e.g. BAT or USDT) instead of on Ethereum blochckain. Maybe the token providers and smart contracts providers will switch from Etherereum to SmartBCH.

$ 0.00
3 years ago