Popular Science: Understand Gas, GasLimit, GasPrice on Ethereum
secondary title
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 power for the development and operation of the Ethereum network ecology. Just as gasoline is for cars, Gas is essential 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, which can better maintain the normal operation of the Ethereum network.At the bottom of the Ethereum system, the amount of Gas consumption is determined for each specified operation and contract method, and each calculation step in the transaction process needs to consume Gas. For example: users who deploy the NEST oracle machine quotation contract need to pay a certain Gas fee to execute this transaction, and Gas is the handling fee charged by the Ethereum system to users. When using the Ethereum network, the maximum value of Gas consumption must be set. When the Gas is consumed or the logic of the smart contract is executed, the execution of the contract will stop.
Tip: Regardless of whether the transaction initiated by the user is successfully packaged or not, the gas fee must be paid; this is like driving halfway home and running out of gas. Even if you fail to get home, the gas consumed has indeed been consumed. So pay for it too.
secondary title
What is GasLimit again?
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 setting of a transaction is too low to fully execute the transaction logic, the system will prompt"out of gas", the transaction will fail
. This transaction will still be packaged into 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 this block. (Users who often deploy smart contracts should have encountered this situation)If the amount of Gas used in the 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 is often mentioned.
That is the GasLimit of a block, that is, the upper limit of the sum of Gas transactions that can be executed in a single Ethereum block.below gas limitWhen each block is packaged, the total amount of 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 miners will determine that the current Gas Limit is sufficient when packaging each transaction. Not enough to package the current deal. If you package a transaction that will exceed the GasLimit of the current block, it will be rejected by the Ethereum network, and the system feedback is "12 million Gas 。
Etherscan GasPrice data
secondary title
The price of a single Gas: GasPrice
1 ETH = 1,000,000,000 Gwei
GasPrice is the price that users are willing to pay for each Gas, and the unit is Gwei.
In addition to obtaining mining block rewards, Ethereum miners always hope that the block contains more gas fees; therefore, when the mining pool packs transactions, it gives priority to packaging transactions that pay more miner fees.
Gas fee for a transaction = GasPrice * GasUsedTherefore, the higher the GasPrice is set, the earlier the transaction is packaged into the block and the sooner it is confirmed
; If the GasPrice is set too low, the transaction will be in the pending state for a long time, queuing up to be packaged by miners. Therefore, when the Ethereum network is congested, if we want to speed up the transaction speed, we need to greatly increase the GasPrice value of the transaction, so that miners can package our transactions first.


