header-langage
简体中文
繁體中文
English
Tiếng Việt
Scan to Download the APP
Partnered With:

Read Gas, GasLimit, GasPrice on ethereum

Read this article in 9 Minutes
Learn about the Gas mechanism on ethereum

Original title: popular science | read Gas, GasLimit, GasPrice on ethereum

Prophetic machine laboratory, babbitt


What is Gas?


Gas is a unit of measurement that exists within ethereum EVM. As the fuel in ethereum network, it provides the power for the development and operation of ethereum network ecology. Gas is as essential to ethereum users and developers as gasoline is to cars.


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


At the bottom of the ethereum system, Gas quantity is determined for each specified operation and contract method, and Gas is consumed for each calculation step during the transaction. For example, a user deploying a NEST predictor quote contract would have to pay a Gas fee to execute the transaction, which is the fee charged by the ethereum system. When using the ethereum network, you must set a maximum value for Gas consumption. When Gas consumption runs out or the smart contract logic runs out, the contract is stopped. Within ethereum, Gas needs to be converted to ETH to make payments.


Tip: whether the transaction initiated by the user is packaged successfully or not, the Gas fee shall be paid; It's like driving home and running half out of gas. Even if you don't make it home, you'll have to pay for it.


What is the GasLimit?


GasLimit is the maximum amount of Gas an ethereum user is willing to pay to successfully execute a transaction logic.


If the GasLimit for a transaction is set too low to allow the transaction logic to fully execute, the system will prompt "out of gas" and the transaction will fail. The deal will still be packaged into the block, and the ethereum assets will be automatically returned, but Gas fees will still be charged as a reward to the miners who packaged the block. (users who frequently deploy smart contracts should have experienced this.)


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


Note that we are referring to the Gas limit for a transaction. In the whole ethereum development process, there is one GasLimit value that is more important and often mentioned, that is, the GasLimit of a block, namely the upper limit of Gas sum of the transactions that can be executed in a single ethereum block.


When each block is packaged, the total GasLimit of all transactions in the current block is determined to determine the number of transactions that can be packaged in the block. Therefore, when each transaction is packaged, miners will determine whether the current Gas volume is enough to package the current transaction. If you package a transaction that will exceed the GasLimit in the current block, the ethereum network will reject it and the system will respond with "below gas limit". After multiple upgrades to ethereum 1.x, one ethereum block currently has a GasLimit value of 12 million Gas.



Etherscan  GasPrice data


Price of a single Gas: GasPrice


GasPrice is the price that the user is willing to pay per Gas in Gwei.


1 ETH = 1,000,000,000 Gwei


Ethereum miners, in addition to being rewarded for digging blocks, always want more Gas in the blocks; So when the pools package deals, they give priority to deals that pay miners more.


Miners' fee for a deal = GasPrice  * & have spent GasUsed


Therefore, the higher the GasPrice is set, the more the transaction is packaged into the block and confirmed; If the GasPrice is set too low, the transaction will be in the pending state for a long time, waiting in line to be packed by the miners. Therefore, if we want to speed up the transaction during ethereum network congestion, we need to significantly increase the GasPrice value of the transaction, so that the miners can package our transaction first.


Above is the definition and relationship of Gas, GasLimit and GasPrice parameters in ethereum network. If you want to be more directly aware of blockchain technology and smart contracts, deploy your own smart contracts on the ethereum chain, or join the NEST price predictor network as a quote miner and participate in the quote.


The original address: https://www.8btc.com/media/587478




Welcome to join the official BlockBeats community:

Telegram Subscription Group: https://t.me/theblockbeats

Telegram Discussion Group: https://t.me/BlockBeats_App

Official Twitter Account: https://twitter.com/BlockBeatsAsia

举报 Correction/Report
Choose Library
Add Library
Cancel
Finish
Add Library
Visible to myself only
Public
Save
Correction/Report
Submit