Detailed explanation of Ethereum EIP-1559 Gas fee calculation method

Detailed explanation of Ethereum EIP-1559 Gas fee calculation method

Original title: "Ethereum EIP-1559 Gas Fee Calculation Guide: Ensuring Smooth Transactions Under Gas Changes"
Written by Blocknative
Translation: Yangz

When Ethereum upgraded its core gas fee market with EIP-1559, transactions moved from a first-price auction to a hybrid system involving base fees and tips. As we’ve covered before, this introduced new complexity to on-chain transactions.

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

New terminology for EIP-1559 transactions

First, a refresher: EIP-1559 changes how Ethereum transaction fees are calculated and where those fees go. Instead of a single gas price, you now have to pay attention to three separate values.

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

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

  • Max Fee Per Gas, this is the absolute maximum amount you are willing to pay per unit of Gas to get your transaction included in a block. For brevity, we will call it the Max Fee.

Transactions that include these new fields are called Type 2, while traditional transactions with the original Gas Price field are still supported and are called Type 0. Note: EIP-1559 does not bring changes to the "Gas Limit" (the maximum amount of Gas that a transaction is authorized to consume).

Determination of basic costs

The base fee is determined by the Ethereum network, not by end users seeking transactions or miners seeking to validate transactions. The base fee is targeted to keep blocks at 50% complete and is based on the contents of the most recently confirmed block. The base fee automatically increases or decreases depending on how complete the new block is.

for example:

  • If the previous block was exactly 50% complete, the base fee will remain the same.

  • If the previous block was a full block (100%), then the base fee for the next block will increase by up to 12.5%.

  • If the previous block was more than 50% complete, but less than 100%, then the base fee will increase by less than 12.5%.

  • If the previous block was a blank block (0%), the base fee of the next block will be reduced by up to 12.5%.

  • If the previous block was more than 0% complete, but less than 50% complete, the base fee will be reduced by less than 12.5%.

This new mechanism is designed to help smooth out transaction fees and prevent sudden spikes in gas fees. The most important thing to remember when it comes to the base fee is that it is 100% automatic and read directly from the network.

Setting priority fees

The top priority fee - also commonly referred to as the miner tip - is an "optional" additional fee paid directly to miners to incentivize them to include your transaction in a block. While the top 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. That said, specific mining pools may choose to set alternative minimum inclusion standards.

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

A subtle difference with the top priority fee is that it represents the maximum tip you are willing to pay to miners. However, if the base fee plus the top priority fee exceeds the maximum fee (see below), the top priority fee will be reduced to meet the cap on the maximum fee. This means that the actual tip may need to be less than your top priority fee, in which case your transaction may be less attractive to miners.

Calculate the maximum cost

Now that we have introduced the basics of base fees and top priority fees, let’s take a look at the somewhat counter-intuitive concept of top fees.

The maximum fee is the absolute maximum amount you are willing to pay per unit of Gas in order to get your transaction confirmed. Here’s where things can get a little confusing — because in most cases, your actual transaction fee will be less than your pre-specified maximum fee. Here’s why:

  • The minimum Gas price for your transaction is the current Base Fee.

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

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

  • Our EIP-1559 compliant Gas Estimator currently uses the following simple heuristic to calculate the recommended maximum fee for any given base fee and highest priority fee combination. Maximum Fee = (2 * Base Fee) + Highest Priority Fee

Doubling the base fee when calculating the maximum fee will ensure that your transaction remains included for six consecutive 100% full blocks. Here is an example.

Illustrative example: In six blocks, from treated to untreated

Suppose your transaction is submitted in block 1, and the base fee at that time is 100.0 GWEI. You choose to set a maximum priority fee of 2.0 GWEI, so your maximum fee is calculated as 2 * 100.0 + 2.0, which is 202.0 GWEI.

But, just as you submit your transaction, a high-profile NFT airdrop occurs and demand on the network surges. Suddenly, every block is a full block — not the 50% discussed above — so the base fee increases by up to 12.5% ​​per block.

therefore:

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

In effect, by setting your maximum fee this way, your transaction is “protected” from becoming too cheap to be processed if the base fee rises rapidly.

But what if the base fee doesn't increase so quickly? You will be charged less than the maximum fee you specify. See the table above.

  • Remember, your transaction was submitted during block 1, when the base fee was 100.0 GWEI. You selected the highest priority fee of 2.0 GWEI, so your maximum fee is calculated to be 202.0 GWEI.

  • Your transaction is confirmed in interval 4, at which point the base fee is 142.2 GWEI.

  • Your transaction fee is determined by the base fee at the time of confirmation plus the price of 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. So, this 57.6 GWEI/Gas is actually "saved" and will remain in your wallet.

  • It’s important to note that your maximum fee is not “taken” from your wallet and then partially “refunded.” Instead, the maximum fee is a threshold for a “maximum authorized fee.”

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

Finally, in the above scenario, what would happen if you did not include a 2x safety factor when calculating the maximum fee, but instead set the maximum fee at the minimum of 102.0 GWEI?

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

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

  • At this point, your transaction will remain pending until the base fee drops and is below the maximum fee of 102.0 GWEI.

  • Alternatively, when the network is highly congested, your transaction may be abandoned entirely.

This is why maximum fees are counter-intuitive:

  • Most of the time — probably the vast majority of the time — the transaction fees you pay will be less than your maximum fee.

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

  • If you choose to take your chances and set your maximum fee too close to the current base fee, you risk having your transaction fail and no longer be eligible for inclusion in a block.

To achieve predictable transaction settlement performance, we recommend building a healthy safety margin into the maximum fee calculation.

EIP-1559 in MetaMask

By default, MetaMask version 10.0.0 automatically sets the highest priority fee for your transaction. You can modify these fees using the "Edit" button, and can choose between Low (slowest confirmation), Medium, or High (fastest confirmation) fees.

In addition, you can manually specify the gas limit, maximum priority fee, and maximum fee for the transaction. Please select Advanced Options and drop down the settings.

Source link: www.8btc.cn

<<:  El Salvador Releases First Official Bitcoin Commercial Video Ad

>>:  Data: Stablecoin circulation on Ethereum exceeds $83 billion

Recommend

Palmistry that affects marriage and family

Palmistry that affects marriage and family 1. Bro...

Ethereum fork is imminent, here are the things you need to know!

Text/Wang Miaomiao from BitWu Team After waiting ...

Your waist shape determines your fortune

Your waist shape determines your fortune 1. Those...

What is a career line?

What is the career line? What is career line? Wha...

What kind of woman is the most vicious?

There is a saying that goes, "A woman has th...

What do you know about wrinkle facial features?

Wrinkles that represent bad luck Having wrinkles ...

Is it reliable to look at the five features? Five features analysis diagram

Is it accurate to judge a person’s appearance by ...

Is a man with a hooked nose good or worthy of your life?

What does a man with a hooked nose look like? A h...

Revealing the facial features of men who have a hard life these days

Whether a person's fate is good or not has a ...

USDC issuer Circle raises $440 million

Circle, the issuer of the stablecoin USDC, announ...

Russia is ready for a massive influx of "bitcoin immigrant miners"

Despite its hesitation about the issue of central...

Auxiliary lines in the palm - Solomon ring

Auxiliary lines in the palm - Solomon ring At the...