Browsing Tag: Gas fee

    Blockchain public chain

    Easy to read Gas,GasLimit,GasPrice on Ethereum

    July 4, 2020

    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.

    Etherscan GasPrice data
    Etherscan GasPrice data

    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.

    ETH authorization
    Blockchain public chain

    What is “authorization” in Ethereum contract interaction?

    June 30, 2020

    As for the “authorization” operation, many new Ethereum users are confused when they first operate the smart contract. I don’t understand what authorization is, let alone why authorization initiates a transaction, and the transaction itself does not carry any assets, and at the same time, it has to pay a miner’s fee.

    In this article, we will explain the nature of “authorization” operation from the perspective of technology.

    When users interact with Ethereum smart contract token assets, they must first approve. So, why do you need authorization?

    quotation for nest oracle

    Let’s give an example of a miners’ quotation for nest oracle:

    • Bob is a nest price maker. When he participates in the ETH/USDT price prediction machine quotation, he needs to transfer the ETH and USDT assets into the quotation contract according to his own quotation data. Here, it is assumed that 10 ETH and 1600 USDT are used to conduct a quotation operation.
    • Then Bob must first authorize the USDT asset to the quotation contract of nest Oracle, so that the quotation contract has the authority to operate the USDT asset in Bob’s wallet, so that the transaction logic related to USDT asset can be executed smoothly when the verifier takes the order within the quotation life cycle.
    • Authorization here is essentially an on chain transaction, requiring users to pay miners’ fees (Gas fees). The purpose is to tell the USDT token contract that target smart contract a has the right to control the number of USDT assets in my wallet X. Then, when the target contract A needs to conduct USDT transactions, it will take the initiative to obtain no more than x USDT assets from the USDT token contract.

    However, in the above case, another question arises. Why only ERC20 tokens such as USDT need to be authorized while ETH does not?

    Technical analysis: because ETH is the native asset of Ethereum network, when transferring money to the target smart contract, the underlying layer of Ethereum network forces the target contract to have a certain receiving method, so the transaction itself can carry ETH assets into the target contract; while ERC20 token only changes the ERC20 token when transferring to the target contract The target contract will not receive any notice for the account book information of the contract itself.

    Therefore, ETH does not need authorization operations like ERC20 token when it interacts with smart contracts.

    To be exact, there are two steps in the authorization operation:

    Step 1: authorize the transaction itself. It is to tell an ERC20 token contract that in the future, a target smart contract address a may come to my wallet account to take x quantity of token assets;

    Step 2: the transaction execution itself. When the logic execution in the target contract A requires the token transaction, contract a will take the initiative to trigger the transfer transaction of ERC20 token to take away the X quantity of the token; on the contrary, if the transaction of the token is not involved, even if it has been authorized, the asset transaction will not really occur.

    In short, after the authorization operation, the token transaction is not necessarily executed, but such a fund operation authority is reserved for the target contract A.

    In order to avoid users’ repeated authorization operations, many smart contract developers usually set the maximum number of tokens authorized to the target smart contract by default. Obviously, there are certain risks in this way. If there is a loophole in the smart contract or the contract administrator does something evil, the user’s token assets will be lost, which is the problem caused by “over authorization“.

    Whether in NEST DAPP or imToken wallet, we often encounter this problem.

    over authorization

    In order to solve the problem of “over authorization”, NEST DAPP has an authorization management page. If a miner does not expect to participate in NEST Oracle quotation in a short time, he can “cancel authorization” to eliminate the security problems caused by existing authorization. imToken wallet also takes some measures, such as “clear authorization information” for each authorization, and has an exclusive DAPP for authorization management, so that users can freely manage their existing authorization.

    The feasibility scheme of skipping authorization operation: by implementing specific transfer logic in ERC20 token contract, that is, a method of forcibly invoking the target contract while transferring money, the current authorization operation can be avoided. However, in order to keep the purity of token contract, the mainstream ERC20 token does not implement this function.