Ethereum
准备好在生产环境中调用了吗?
免费套餐涵盖个人项目。按量付费,无需绑卡即可扩展。
Ethereum
免费套餐涵盖个人项目。按量付费,无需绑卡即可扩展。
Gas is where Ethereum's economics meet your application's reliability. Every block has a gas limit, every transaction pays in ETH for the computation it triggers, and since EIP-1559 the base price floor moves with demand on each new block. Get the fee wrong on the low side and your transaction sits stuck while the base fee rises past it; overpay and you've burned user funds for no benefit. Reading gas at the block level — the limit, the target, the current baseFeePerGas — is how you set fees that actually land.
Done well, gas management means transactions that confirm in the slot you expect at a price your users accept. That's the difference between a checkout that completes and one that hangs. This guide covers the block-level mechanics on chain 1: the gas limit and target, how EIP-1559's base fee and priority tip combine, and the estimation strategies that keep type-2 transactions both cheap and reliably included.
maxFeePerGas (the most you'll pay per gas) and maxPriorityFeePerGas (the tip to the validator). You pay the block's current baseFeePerGas — which is burned, removing ETH from supply — plus your tip, never more than your max. Read baseFeePerGas off the latest block and eth_maxPriorityFeePerGas for a sane tip; eth_feeHistory gives you the recent distribution to set both intelligently.eth_estimateGas tells you the gas units a call will consume, but it can under-report for paths whose cost depends on state, so pad it. For the price, a conservative maxFeePerGas (well above the current base fee) buys inclusion through fee spikes at the risk of overpaying; a tight one saves ETH but risks getting stranded when the base fee climbs. The legacy eth_gasPrice collapses both into one number and is best avoided for new code.baseFeePerGas from the latest block and a tip from eth_maxPriorityFeePerGas right before signing, then set maxFeePerGas to roughly twice the base fee plus the tip so you stay included even if the next few blocks run hot. Re-quote on every transaction, since the base fee can shift meaningfully within a couple of slots.eth_feeHistory to time them.eth_estimateGas for the units, then add headroom (commonly 10 to 25%) so a slightly more expensive execution path doesn't run out of gas and revert. Don't pad blindly to the block limit, though — an over-large limit can raise the cost of some operations and wastes nothing only if execution stays cheap.maxFeePerGas and a generous tip — being outbid costs more than overpaying. A routine user transfer or a background batch wants a conservative max close to the current base fee, accepting that it may wait a few blocks to save ETH.