Explore the Ethereum Concepts

Beginner2/22/2024, 5:31:36 AM
This article provides an overview of Ethereum gas fees.

Forward the Original Title‘All You Need to Know about Ethereum Gas, Gas Limit, Gas Price, Gas Fee, Base Fee, Max Fee’

In Ethereum or other networks), to execute specific operations like sending tokens, storage, or token exchange, a certain amount of fuel is consumed, referred to as gas. This is similar to a car needing gasoline to run. In Ethereum, various interactions require the consumption of gas. For example:

Suppose driving from point A to point B requires 10 liters of gas, priced at $8 per liter. Then, the cost of gas from A to B would be: 10 * 8 = $80.

Similarly, in the Ethereum network, suppose executing the operation of sending tokens requires the consumption of 21,000 units of gas, with a price of 100 gwei per unit. The cost of executing this transaction would be: 21,000 * 100 = 2,100,000 gwei.

Why is Gas Needed?

We all know that a crucial strategy in web2 is providing services for free to attract traffic and achieve monetization. So, why doesn’t Ethereum follow the same approach in web3?

Charging gas fees not only serves as an incentive for rewarding miners but also acts as a deterrent against malicious attacks. Without gas fees, attackers could deploy numerous infinite-loop contracts and continuously run them by sending transactions, hijacking a significant portion of the network’s computational power and causing a system shutdown. By specifying gas consumption, Ethereum prevents malicious infinite loops, avoiding resource wastage. When all gas is consumed, the operation stops, similar to a car stopping when it runs out of gas, preventing further exploitation.

Gas Limit

What is Gas Limit?

In the earlier example, to calculate how much money was spent on gas from point A to point B, you needed to know the gas price per liter and the amount of gas consumed (liters used).

Similarly, in the Ethereum network, to calculate the cost (transaction fee) of a specific operation, you need to know the gas price and the amount of gas consumed.

The amount of gas to be consumed is set by the contract creator. Different contracts and different types of operations consume different amounts of gas. The more complex the operation, the more gas it requires. Therefore, estimating the exact gas consumption in advance is challenging. To address this, gas limit is set. Unutilized gas would be returned to the user.

When calculating the amount of gas consumed, wallet providers like Metamask often directly provide the gas limit. If the actual consumption amount is less than the gas limit, the remainder is refunded. If the actual consumption amount exceeds the gas limit, the transaction cannot be executed.

Suppose a Ethereum network transfer requires 21,000 units of gas, and the gas limit is set to 50,000, but only 21,000 is consumed in reality. Then, the remaining 29,000 will be automatically refunded. However, if the actual consumption is 51,000, and you’ve set the gas limit to 50,000, the transaction will not be successful, and the 50,000 gas will not be refunded.

Therefore, attempting to reduce transaction fees by decreasing the gas limit may have the opposite effect: the transaction might fail and the handling fee will still be deducted.

How is Gas Limit Determined?

The value of gas limit is generally automatically provided by wallet providers and usually does not need manual modification or adjustment.

Gas Price

What is Gas Price?

Gas price refers to the price/unit of gas, usually expressed in Gwei.

How to Determine Gas Price

After the London upgrade on August 5, 2021, gas price is divivded to two parts: the base fee and the max priority fee.

「1. Base fee」

The base fee is the basic cost. Each block has a base fee as the minimum price. To be included in a block, the gas price of a transaction must be greater than or equal to the base fee, which is decided by Ethereum itself. So we will not discuss the base fee here.

「2. Max priority fee」

In the mechanism of gas fees on the Ethereum network, similar to when you add tips during peak hours on a ride-hailing app, adding a tip may prioritize your transaction. It’s essential to note that the base fee changes in real-time based on network congestion and can be checked on websites, while the tip can be adjusted manually, generally higher but not lower.

「3. Max fee」

This is the maximum cost per unit of gas. The max fee is the absolute maximum amount you are willing to pay per unit of gas to confirm your transaction. In most cases, your actual transaction cost will be lower than the specified max fee, and your minimum gas price for the transaction is the current base fee. However, if the base fee increases while your transaction is not completed, your transaction might get stuck, fail, or be abandoned. Therefore, to achieve predictable transaction settlements under EIP-1559, it is currently considered best practice to set a max fee that anticipates an increase in the expected base fee.

The specific transaction information in the above image includes:

  • 1、Base fee: 27.630981243 Gwei
  • 2、Max priority fee: 0.01 Gwei
  • 3、Max fee: 57.802896536 Gwei
  • 4、Gas price: base fee + max priority = 27.640981243 Gwei
  • 5、Gas limit: 46,097
  • 6、Usage by Txn: 46,097 (Actual gas amount used in the transaction)
  • 7、Gas fee: gas price * Usage by Txn = 1274166.312358571 Gwei = 0.001274166312358571ETH

Disclaimer:

  1. This article is reprinted from [Web3星云], Forward the Original Title‘All You Need to Know about Ethereum Gas, Gas Limit, Gas Price, Gas Fee, Base Fee, Max Fee’,All copyrights belong to the original author [dogwang]. If there are objections to this reprint, please contact the Gate Learn team, and they will handle it promptly.
  2. Liability Disclaimer: The views and opinions expressed in this article are solely those of the author and do not constitute any investment advice.
  3. Translations of the article into other languages are done by the Gate Learn team. Unless mentioned, copying, distributing, or plagiarizing the translated articles is prohibited.

Explore the Ethereum Concepts

Beginner2/22/2024, 5:31:36 AM
This article provides an overview of Ethereum gas fees.

Forward the Original Title‘All You Need to Know about Ethereum Gas, Gas Limit, Gas Price, Gas Fee, Base Fee, Max Fee’

In Ethereum or other networks), to execute specific operations like sending tokens, storage, or token exchange, a certain amount of fuel is consumed, referred to as gas. This is similar to a car needing gasoline to run. In Ethereum, various interactions require the consumption of gas. For example:

Suppose driving from point A to point B requires 10 liters of gas, priced at $8 per liter. Then, the cost of gas from A to B would be: 10 * 8 = $80.

Similarly, in the Ethereum network, suppose executing the operation of sending tokens requires the consumption of 21,000 units of gas, with a price of 100 gwei per unit. The cost of executing this transaction would be: 21,000 * 100 = 2,100,000 gwei.

Why is Gas Needed?

We all know that a crucial strategy in web2 is providing services for free to attract traffic and achieve monetization. So, why doesn’t Ethereum follow the same approach in web3?

Charging gas fees not only serves as an incentive for rewarding miners but also acts as a deterrent against malicious attacks. Without gas fees, attackers could deploy numerous infinite-loop contracts and continuously run them by sending transactions, hijacking a significant portion of the network’s computational power and causing a system shutdown. By specifying gas consumption, Ethereum prevents malicious infinite loops, avoiding resource wastage. When all gas is consumed, the operation stops, similar to a car stopping when it runs out of gas, preventing further exploitation.

Gas Limit

What is Gas Limit?

In the earlier example, to calculate how much money was spent on gas from point A to point B, you needed to know the gas price per liter and the amount of gas consumed (liters used).

Similarly, in the Ethereum network, to calculate the cost (transaction fee) of a specific operation, you need to know the gas price and the amount of gas consumed.

The amount of gas to be consumed is set by the contract creator. Different contracts and different types of operations consume different amounts of gas. The more complex the operation, the more gas it requires. Therefore, estimating the exact gas consumption in advance is challenging. To address this, gas limit is set. Unutilized gas would be returned to the user.

When calculating the amount of gas consumed, wallet providers like Metamask often directly provide the gas limit. If the actual consumption amount is less than the gas limit, the remainder is refunded. If the actual consumption amount exceeds the gas limit, the transaction cannot be executed.

Suppose a Ethereum network transfer requires 21,000 units of gas, and the gas limit is set to 50,000, but only 21,000 is consumed in reality. Then, the remaining 29,000 will be automatically refunded. However, if the actual consumption is 51,000, and you’ve set the gas limit to 50,000, the transaction will not be successful, and the 50,000 gas will not be refunded.

Therefore, attempting to reduce transaction fees by decreasing the gas limit may have the opposite effect: the transaction might fail and the handling fee will still be deducted.

How is Gas Limit Determined?

The value of gas limit is generally automatically provided by wallet providers and usually does not need manual modification or adjustment.

Gas Price

What is Gas Price?

Gas price refers to the price/unit of gas, usually expressed in Gwei.

How to Determine Gas Price

After the London upgrade on August 5, 2021, gas price is divivded to two parts: the base fee and the max priority fee.

「1. Base fee」

The base fee is the basic cost. Each block has a base fee as the minimum price. To be included in a block, the gas price of a transaction must be greater than or equal to the base fee, which is decided by Ethereum itself. So we will not discuss the base fee here.

「2. Max priority fee」

In the mechanism of gas fees on the Ethereum network, similar to when you add tips during peak hours on a ride-hailing app, adding a tip may prioritize your transaction. It’s essential to note that the base fee changes in real-time based on network congestion and can be checked on websites, while the tip can be adjusted manually, generally higher but not lower.

「3. Max fee」

This is the maximum cost per unit of gas. The max fee is the absolute maximum amount you are willing to pay per unit of gas to confirm your transaction. In most cases, your actual transaction cost will be lower than the specified max fee, and your minimum gas price for the transaction is the current base fee. However, if the base fee increases while your transaction is not completed, your transaction might get stuck, fail, or be abandoned. Therefore, to achieve predictable transaction settlements under EIP-1559, it is currently considered best practice to set a max fee that anticipates an increase in the expected base fee.

The specific transaction information in the above image includes:

  • 1、Base fee: 27.630981243 Gwei
  • 2、Max priority fee: 0.01 Gwei
  • 3、Max fee: 57.802896536 Gwei
  • 4、Gas price: base fee + max priority = 27.640981243 Gwei
  • 5、Gas limit: 46,097
  • 6、Usage by Txn: 46,097 (Actual gas amount used in the transaction)
  • 7、Gas fee: gas price * Usage by Txn = 1274166.312358571 Gwei = 0.001274166312358571ETH

Disclaimer:

  1. This article is reprinted from [Web3星云], Forward the Original Title‘All You Need to Know about Ethereum Gas, Gas Limit, Gas Price, Gas Fee, Base Fee, Max Fee’,All copyrights belong to the original author [dogwang]. If there are objections to this reprint, please contact the Gate Learn team, and they will handle it promptly.
  2. Liability Disclaimer: The views and opinions expressed in this article are solely those of the author and do not constitute any investment advice.
  3. Translations of the article into other languages are done by the Gate Learn team. Unless mentioned, copying, distributing, or plagiarizing the translated articles is prohibited.
Start Now
Sign up and get a
$100
Voucher!