Home News Explain the calculation method of Ethereum EIP-1559 Gas fee in detail

Explain the calculation method of Ethereum EIP-1559 Gas fee in detail

Loading

In order to achieve predictable transaction settlement performance, it is recommended to include a healthy safety factor in the calculation of the maximum fee.

Original title: ” Ethereum EIP-1559 Gas Cost Calculation Guide: Ensure Smooth Transaction under Gas Change
Written by: Blocknative
Translation: Yangz

When Ethereum upgraded the core Gas fee market with EIP-1559, the transaction changed from the first price auction to a hybrid system involving basic fees and tips. As we have introduced before, this introduces a new level of complexity for on-chain transactions.

To further clarify this point, we will explain the new terminology and how to deal with the core variables related to EIP-1559 transaction fees.

EIP-1559 New terminology for transactions

First of all, review: EIP-1559 changes the calculation method of Ethereum transaction fees and the whereabouts of these fees. It is now necessary to pay attention to three independent values, not a single Gas price.

  • The Base Fee, which is determined by the network itself, is subsequently destroyed.

  • Max Priority Fee (Max Priority Fee), which is optional, determined by the user, and paid directly to the miner.

  • The maximum fee per unit of Gas (Max Fee Per Gas), which is the highest absolute value you are willing to pay per unit of Gas to include your transaction in the block. For the sake of brevity, we will call it the maximum cost.

The transaction that includes these new fields is called type 2, while the traditional transaction with the original Gas price field is still supported and is called type 0. Note: EIP-1559 does not change the “Gas limit” (the maximum amount of gas that a transaction is authorized to consume).

Determination of basic expenses

The basic fee is determined by the Ethereum network, not by end users seeking transactions or miners seeking to verify transactions. The goal of the basic fee is to make the block complete at 50% and based on the recently confirmed block content. According to the completeness of the new block, the basic fee will automatically increase or decrease.

for example:

  • If the integrity of the previous block is exactly 50%, then the basic fee will remain unchanged.

  • If the previous block is a complete block (100%), the basic fee of the next block will increase by up to 12.5%.

  • If the integrity of the previous block exceeds 50% but is less than 100%, the basic fee will increase by less than 12.5%.

  • If the previous block is a blank block (0%), then the basic cost of the next block will be reduced by up to 12.5%.

  • If the integrity of the previous block exceeds 0% but is less than 50%, the basic fee will be reduced by less than 12.5%.

This new mechanism is to help smooth transaction fees and prevent gas fees from rising suddenly. When it comes to basic fees, the most important thing to remember is: it is 100% automatic and can be read directly from the Internet.

Set priority fee

The highest priority fee-often referred to as a miner tip-is an “optional” additional fee that is paid directly to the miners to incentivize them to include your transaction in the block. Although the highest priority fee is technically optional, most network participants currently estimate that transactions generally require a tip of at least 2.0 GWEI to be included. Nevertheless, certain mining pools may choose to set alternative minimum inclusion criteria.

For “typical” transactions submitted under normal, uncongested network conditions, the highest priority fee needs to be close to 2.0 GWEI. However, for transactions whose order or inclusion in the next block is important, or when the network is highly congested, a higher highest priority fee may be required to prioritize your transaction.

One subtle difference in the highest priority fee is that it represents the highest tip you are willing to pay to a miner. However, if the base fee plus the highest priority fee exceeds the highest fee (see below), the highest priority fee will be reduced to meet the upper limit of the highest fee. This means that the actual tip may need to be less than your highest priority fee, in which case your transaction may be less attractive to miners.

Calculate the maximum cost

After introducing the basics of basic fees and highest priority fees, let’s take a look at the somewhat counter-intuitive concept of highest fees.

The maximum fee is the absolute maximum amount you are willing to pay per unit of Gas to make your transaction confirmed. Here, things can get a little messy – because in most cases, your actual transaction fees will be lower than the maximum fees you pre-specify. Here are the reasons:

  • The lowest gas price you trade is the current basic fee.

  • However, what if the benchmark fee increases before your transaction is completed? Then, your transaction may be stuck, or fail or be abandoned.

  • Therefore, in order to achieve predictable transaction settlement under EIP-1559, it is currently believed that the best practice is to set a maximum fee that is expected to increase the basic fee. But how much should it increase? What is the reason?

  • Our Gas Estimator that complies with the EIP-1559 standard currently uses the following simple heuristic method to calculate the recommended maximum cost for any given combination of base cost and highest priority cost. Highest cost = (2 * Basic cost) + Highest priority cost

When calculating the maximum fee, double the basic fee to ensure that your transaction can be included in six consecutive 100% complete blocks. The following are related examples.

Illustrative example: in six blocks, from processing to not being processed

Assuming that your transaction was submitted in block 1, the basic fee at that time was 100.0 GWEI. You choose to set the highest priority fee of 2.0 GWEI, so your highest fee is calculated as 2 * 100.0 + 2.0, which is 202.0 GWEI.

However, just when you submitted your transaction, there was a high-profile NFT airdrop, and network demand surged. Suddenly, each block becomes a complete block-instead of the 50% discussed above-so the base fee increases by up to 12.5% ​​per block.

therefore:

Explain the calculation method of Ethereum EIP-1559 Gas fee in detail

As you can see, it takes 6 consecutive 100% complete blocks to double the basic fee – in this example, from 100.0 GWEI to 202.7 GWEI.

In fact, by setting your maximum fee in this way, your transaction will be “protected” to prevent the price from becoming too low and unable to be processed when the benchmark fee rises rapidly.

However, what if the basic cost does not increase so rapidly? You will be charged less than the maximum fee you specified. Refer to the above table.

  • Remember, your transaction was submitted during block 1, when the basic fee was 100.0 GWEI. You have selected the highest priority fee of 2.0 GWEI, so your highest fee is calculated as 202.0 GWEI.

  • Your transaction is confirmed in the 4th interval, and the basic fee at this time is 142.2 GWEI.

  • Your transaction fee is determined by the price of the basic fee at the time of confirmation plus your highest priority fee. Therefore, you will pay 144.2 GWEI/Gas for this transaction.

  • This is 57.6 GWEI/Gas less than the maximum fee you specified. Then, this 57.6 GWEI/Gas is actually “saved” and will remain in your wallet.

  • It is worth noting that your highest fee was not “withdrawn” from your wallet, and then part of it was “refunded.” On the contrary, the maximum fee is the threshold of the “maximum authorization fee”.

  • If your transaction is not confirmed before the 6th block, it will become unprocessable during the 7th block-it is no longer a candidate because its maximum fee of 202.0 GWEI is just below The new base fee is 202.7 GWEI.

Finally, under the above circumstances, if you did not include a factor of safety of 2 when calculating the maximum cost, but set the maximum cost to the lowest 102.0 GWEI, what would happen?

  • Your transaction can be processed in the first range because your maximum fee is still higher than the base fee of 100.0 GWEI.

  • However, by the second block, your maximum fee is lower than the new base fee of 112.5 GWEI.

  • At this time, your transaction will remain pending until the basic fee drops and falls below the maximum fee of 102.0 GWEI.

  • Or, when the network is highly congested, your transaction may be completely abandoned.

This is why the highest fees are counter-intuitive:

  • Most of the time–perhaps most of the time–the transaction fee you pay will be less than your maximum fee.

  • But sometimes, especially during periods of high network congestion, you will be charged the highest fees.

  • If you choose to take your luck and set your maximum fee too close to the current basic fee, then you may fail your transaction and no longer be eligible to be included in the block.

In order to achieve predictable transaction settlement performance, we recommend adding a healthy safety factor to the calculation of the maximum fee.

EIP-1559 in MetaMask

By default, MetaMask version 10.0.0 will automatically set the highest priority fee for transactions. You can use the “Edit” button to modify these fees. You can choose low (slowest confirmation speed), medium or high (fastest confirmation speed) fees.

In addition, you must manually specify the gas limit, highest priority fee, and highest fee for the transaction. For details, please select advanced options and pull down settings.

Source link: www.8btc.cn

Disclaimer: As a blockchain information platform, the articles published on this site only represent the author’s personal views, and have nothing to do with the position of ChainNews. The information, opinions, etc. in the article are for reference only, and are not intended as or regarded as actual investment advice.

Adblock test (Why?)