Easily understand Gas, GasLimit, GasPrice on EthereumsteemCreated with Sketch.

in hive-110112 •  4 years ago 

image.png

What is Gas?

Gas exists inside the Ethereum EVM and is a unit of measurement for computing workload. As the fuel in the Ethereum network, it provides impetus for the development and operation of the Ethereum network ecology. Just like the role of gasoline for cars, Gas is indispensable for Ethereum users and developers.

On the one hand, Gas is used to reward Ethereum miners for packaging blocks; on the other hand, its existence raises the threshold for malicious transactions and can better maintain the normal operation of the Ethereum network.

At the bottom of the Ethereum system, the consumption of Gas is determined for each prescribed operation and contract method, and each operation step in the transaction process needs to consume Gas. For example, the user who deploys the NEST oracle quotation contract needs to pay a certain gas fee to execute this transaction, and the gas is the fee charged by the Ethereum system to the user. When using the Ethereum network, the maximum gas consumption must be set. When the gas is consumed or the smart contract logic is executed, the contract will stop executing. In the Ethereum system, Gas needs to be converted into ETH for payment.

Tip: No matter whether the transaction initiated by the user is packaged successfully, you must pay the Gas fee; this is like when you drive home and run out of gas halfway, even if you fail to get home, the gas you consumed has indeed been consumed. So pay for it.

image.png

What is GasLimit?

GasLimit is the maximum amount of Gas that Ethereum users are willing to pay for the successful execution of a certain transaction logic.

If the GasLimit of a transaction is set too low to fully execute the transaction logic, the system will prompt "out of gas" and the transaction will fail. The transaction will still be packaged in the block, and the Ethereum assets carried in the transaction will be automatically returned, but the Gas fee will still be charged, and the fee will be issued as a reward to the miner who packaged the block. (Users who often deploy smart contracts should have encountered this situation)

If the amount of Gas used by this transaction is less than or equal to the GasLimit you set, it will be packaged successfully. The total amount of Gas actually consumed in the execution of this transaction is GasUsed, and the unused Gas will be returned to the transaction initiation address.

Please note that the GasLimit we are talking about here refers to the gas limit of a transaction. Throughout the development of Ethereum, there is also a GasLimit value that is more important and often mentioned, that is, the GasLimit of a block, that is, the upper limit of the sum of Gas that can be executed in a single Ethereum block.

When each block is packaged, the total GasLimit of all transactions in the current block will be determined to determine the number of transactions that can be packaged in the block, so the miner will determine that the current gas amount is sufficient when packaging each transaction Not enough to pack the current deal. If you package a transaction that exceeds the GasLimit of the current block, it will be rejected by the Ethereum network and the system will respond as "below gas limit". After multiple upgrades of Ethereum 1.x, the current GasLimit value of an Ethereum block is 12 million Gas.

image.png

The price of a single Gas: GasPrice

GasPrice is the price that users are willing to pay for each Gas, and the unit is Gwei.

1 ETH = 1,000,000,000 Gwei

In addition to getting rewards for mining blocks, Ethereum miners always hope that the block contains more gas fees; therefore, when the mining pool packs transactions, it is the priority to package and pay more miners' fees.

Miner fee for a transaction = GasPrice * GasUsed

Therefore, the higher the GasPrice setting, the earlier the transaction will be packaged into the block and the sooner it will be confirmed; if the GasPrice setting is too low, the transaction will be in the pending state for a long time, waiting in line to be packaged by the miner. Therefore, when the Ethereum network is congested, if we want to speed up the transaction, we need to greatly increase the GasPrice value of the transaction so that the miners can prioritize our transactions.

The above is about the definition and relationship of the Gas, GasLimit, and GasPrice parameters in the Ethereum network. If you want to have a more direct perception of blockchain technology and smart contracts, then quickly deploy your own smart contracts on the Ethereum chain, or join the NEST price oracle network, become a quotation miner, and participate in oracle quotations.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Very informative thanks

Indians can't buy this type of technology 😔