0Pricing
Web3 & DApp Development Fundamentals · 课时

Gas 限制与费用

EIP-1559 基础

Gas 限制与费用 是 CoddyKit 上的免费 Web3 & DApp Development Fundamentals 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Web3 & DApp Development Fundamentals 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Web3 & DApp Development Fundamentals 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Controlling What You Spend

You decide how much computation to allow and how much to pay. The two key controls are the gas limit and the fee parameters.

This lesson covers both, including the EIP-1559 fee model.

The Gas Limit

The gas limit is the maximum amount of gas you authorize a transaction to consume.

A simple ETH transfer needs 21000; complex contract calls need more. Setting it too low causes an out-of-gas revert.

simple transfer:  gasLimit = 21000
token transfer:   gasLimit ~ 65000
complex DeFi swap: gasLimit ~ 200000+

Out of Gas

If execution uses more gas than your limit, it stops and reverts all state changes.

Critically, you still pay for the gas already burned — running out of gas does not give you a refund.

Block Gas Limit

Each block also has a block gas limit — the total gas all its transactions may consume.

This caps how much computation fits in one block, keeping block processing fast across the network.

Before EIP-1559

Originally, fees worked as a blind auction: you bid a gas price and validators picked the highest bids.

This led to overpaying and unpredictable fees during congestion. EIP-1559 reformed this in 2021.

EIP-1559: Base Fee

EIP-1559 introduced a base fee — a per-block fee set automatically by the protocol based on network demand.

The base fee rises when blocks are full and falls when they are empty, making fees more predictable.

block full   -> base fee rises
block empty  -> base fee falls
target: blocks ~50% full

The Burned Base Fee

The base fee is burned — permanently destroyed rather than paid to validators.

This removes the incentive for validators to artificially inflate fees and makes ETH mildly deflationary under heavy use.

Priority Fee (Tip)

To incentivize validators, you add a priority fee, or tip, on top of the base fee.

A higher tip encourages validators to include your transaction sooner during congestion.

totalFee = base fee + priority fee
base fee  -> burned
priority fee (tip) -> validator

Max Fee per Gas

You set a maxFeePerGas — the most you will pay per gas unit total. You also set a maxPriorityFeePerGas for the tip.

If the base fee is below your max, you are refunded the difference. You never overpay beyond your cap.

maxFeePerGas          = 50 gwei
maxPriorityFeePerGas  = 2 gwei
actual base fee       = 30 gwei
paid = 30 + 2 = 32 gwei (refunded 18)

Estimating Gas

Wallets and tools call eth_estimateGas to predict how much gas a transaction needs.

Good estimates avoid out-of-gas failures while not over-reserving gas unnecessarily.

Putting It Together

The gas limit caps computation; EIP-1559 splits the price into a burned base fee plus a validator tip.

Your maxFeePerGas guards against overpaying while ensuring inclusion.

Quick Check

Test your EIP-1559 knowledge.

Recap: Gas Limits and Fees

You learned that:

  • The gas limit caps how much gas a transaction may use
  • Running out of gas reverts but still costs you
  • EIP-1559 uses a burned base fee plus a validator tip
  • maxFeePerGas caps your total cost per unit

Next: nonces and ordering.

常见问题解答

「Gas 限制与费用」课时是免费的吗?

是的 — 「Gas 限制与费用」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Web3 & DApp Development Fundamentals 课程的其余内容,请升级到 CoddyKit PRO。 Web3 & DApp Development Fundamentals 课程共包含 4 节课。

「Gas 限制与费用」这节课中我会学到什么?

EIP-1559 基础 你通过在浏览器中直接运行的动手代码来练习 Web3 & DApp Development Fundamentals,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Web3 & DApp Development Fundamentals 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Web3 & DApp Development Fundamentals 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。

「Gas 限制与费用」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Web3 & DApp Development Fundamentals 课中编写并运行代码吗?

能。每节 Web3 & DApp Development Fundamentals 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 什么是 Gas
  2. 交易生命周期
  3. Gas 限制与费用
  4. Nonce 与排序
← 返回 Web3 & DApp Development Fundamentals