How to understand Gas/ Gas Price/ Gas Limit?

When many friends come into contact with Ethereum for the first time, they will not understand what Gas is, let alone what Gas Price and Gas Limit do. This article will introduce and clarify the relationship between these three one by one. I believe you will understand these three gas-related concepts in Ethereum after reading it.

If you want to start learning Ethereum DApp development right away, you can visit the excellent online interactive tutorial provided by Huizhi.com:

Gas

Gas corresponds to the actual operation steps of the Ethereum Virtual Machine (EVM) in a transaction. Simpler transactions, such as simple ether transfer transactions, require fewer steps and require less gas. Conversely, if some complex operations are to be calculated, the consumption of Gas will be large. Therefore, the more computations the EVM needs to perform in the transaction you submit, the higher the gas consumption required.

Gas Price

Gas Price is how much Eth you are willing to pay for a unit of Gas, generally using Gwei as the unit. So the higher the Gas Price, the more Eth will be paid for each operation step in the transaction.

You may be unfamiliar with the unit Gwei. Gwei is actually 10 ^ -9 Eth, which means 1 Gwei = 0.000000001 Eth. So, when you set Gas price = 20 Gwei , it means that you are willing to pay 0.00000002 Eth for a single step operation.

Having said that, if you are smart, you will realize that the calculation formula of Ethereum's fee is very simple:

交易手续费(Tx Fee) = 实际运行步数(Actual Gas Used) * 单步价格(Gas Price)

For example, your transaction requires Ethereum to perform 50 steps to complete the operation. Assuming that the Gas Price you set is 2 Gwei, then the handling fee for the entire transaction is 50 * 2 = 100 Gwei.

Gas Limit

Gas Limit is the upper limit of Gas available in a transaction, that is, how many steps will be performed in your transaction at most. Due to the different complexity of transactions, the exact gas consumption will not be known until the transaction is completed, so before you submit the transaction, you need to set a gas consumption limit for the transaction.

If the transaction you submitted has not been completed, and the gas consumption has exceeded the Gas Limit you set, then the transaction will be cancelled, and the transaction fee that has been consumed will also be deducted-because you want to reward those who have paid the labor. miner. If the transaction has been completed and the gas consumed has not reached the Gas Limit, then the transaction service fee will only be charged based on the actual gas consumed. In other words, the highest possible service fee for a transaction is Gas Limit * Gas​​​ Price.

Finally, it is worth mentioning that the higher the Gas Price, the faster the transaction you submit will be accepted by the miners. But usually people are reluctant to pay more fees, so how much gas price should be set to ensure that transactions are confirmed on the blockchain within normal time (eg 10 mins)? This website can help you. As of this writing, 1 Gwei of Gas Price ensures that transactions are accepted in around 50 seconds.

Original: 1 minute to find out Gas/ Gas Price/ Gas Limit

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325474398&siteId=291194637