What is Gas?
Gas exists in the EVM of Ethereum, and is the unit of measurement for calculating workload. As the fuel of Ethereum network, it provides power for the development and operation of Ethereum network ecology. Just as gasoline plays a role in automobiles, Gas is essential for Ethereum users and developers.
On the one hand, Gas is used to reward Ethereum miners to pack blocks; on the other hand, its existence improves the threshold of malicious transactions, which can better maintain the normal operation of Ethereum network.
In the bottom layer of Ethereum system, Gas consumption is determined for each specified operation and contract method, and Gas consumption is required for each operation step in the transaction process. For example, the user deploying the NEST Oracle quotation contract needs to pay a certain Gas fee to execute the transaction, and Gas is the service charge charged by the Ethereum system. When using Ethereum network, the maximum value of Gas consumption must be set. When the Gas consumption is finished or the smart contract logic is completed, the execution of the contract will be stopped. In Ethereum system, Gas needs to be converted into ETH for payment.
Tip: no matter whether the transaction initiated by the user is packaged successfully or not, the Gas fee must be paid. This is just like driving home on the way home and running out of Gas. Even if you don’t get home successfully, the gasoline consumed has indeed been consumed, so you have to pay for it.
What is GasLimit?
GasLimit is the maximum amount of Gas that Ethereum users are willing to pay for the successful execution of a transaction logic.
If the GasLimit of a transaction is set too low to complete the transaction logic, the system will prompt “out of Gas” and the transaction will fail. The 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, which will be paid as a reward to the miners who pack the block. (users who often deploy smart contracts should have encountered this situation)
If the number 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 consumed in the execution of this transaction is GasUsed, and the unused Gas will be returned to the transaction initiation address.
Please note that GasLimit here refers to the Gas cap of a transaction. In the whole development process 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 total Gas of the transactions that can be executed in a single Ethereum block.
When each block is packed, the total GasLimit of all transactions in the current block will be determined, so as to determine the number of transactions that can be packed in the block. Therefore, when packing each transaction, miners will judge whether the current Gas volume is enough to package the current transaction. 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 will be “below Gas limit”. After several upgrades of Ethereum 1. X, the GasLimit value of an Ethereum block is 12 million Gas.
Price of single Gas: GasPrice
GasPrice is the price a user is willing to pay for each Gas, in Gwei.
1 ETH = 1,000,000,000 Gwei
In addition to the award of mining block, Ethereum miners always hope that more Gas fees will be included in the block; therefore, when the mining pool packs the transaction, it will give priority to the transaction that pays more miners’ fees.
Miner’s fee for one transaction = GasPrice * GasUsed
Therefore, the higher the GasPrice is set, the earlier the transaction is packed into the block and the more confirmed; if the GasPrice setting is too low, the transaction will be in the pending state for a long time, waiting for the miner to pack. 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, and let the miners give priority to packing our transactions.
The above is about the definition and relationship of Gas, GasLimit and GasPrice parameters in Ethereum network. If you want to have a more direct perception of blockchain technology and smart contracts, you can quickly deploy your own smart contract on the Ethereum chain, or join the NEST price Oracle network to become a quotation miner and participate in the Oracle quotation.