gas
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMonad's gas pricing is EIP-1559 compatible but differs from Ethereum in critical ways. If you're building apps that submit transactions, estimate gas, or display gas costs, you need to understand these differences.
Monad的Gas定价兼容EIP-1559,但在关键方面与Ethereum存在差异。如果你正在开发提交交易、估算Gas或显示Gas成本的应用,就需要了解这些差异。
Key Difference: Monad Charges on Gas Limit, Not Gas Used
核心差异:Monad基于Gas上限收费,而非实际消耗的Gas
On Ethereum, users pay for the gas actually consumed by their transaction. On Monad, users pay based on the gas limit they set:
gas_paid = gas_limit * price_per_gasThis exists because Monad uses asynchronous execution — block leaders build blocks before executing them, so actual gas consumption isn't known at inclusion time. This prevents DOS attacks where transactions claim cheap gas but consume expensive computation.
What this means for developers:
- Setting an unnecessarily high gas limit directly costs users more MON.
- Always set tight, accurate gas limits especially for transactions with known fixed costs.
- For native MON transfers, the gas cost is always 21,000. Hardcode this instead of relying on .
eth_estimateGas
在Ethereum上,用户为交易实际消耗的Gas付费。而在Monad上,用户根据自己设置的Gas上限付费:
gas_paid = gas_limit * price_per_gas这种机制存在的原因是Monad采用异步执行——区块领导者在执行前就构建区块,因此在交易纳入时无法得知实际Gas消耗。这可以防止DOS攻击,即交易声称使用低价Gas但实际消耗大量昂贵计算资源的情况。
对开发者的意义:
- 设置过高的Gas上限会直接让用户花费更多MON。
- 始终设置精准的Gas上限,尤其是对于已知固定成本的交易。
- 对于原生MON转账,Gas成本始终为21,000。请硬编码这个值,不要依赖。
eth_estimateGas
EIP-1559 Transaction Pricing
EIP-1559交易定价
Monad uses type 2 (EIP-1559) transactions:
price_per_gas = min(base_price_per_gas + priority_price_per_gas, max_price_per_gas)Users specify two values when signing:
- — tip for transaction prioritization within a block
priority_price_per_gas - — safety cap on total gas price
max_price_per_gas
The network controls , which is the same for all transactions in a block.
base_price_per_gasMonad使用类型2(EIP-1559)交易:
price_per_gas = min(base_price_per_gas + priority_price_per_gas, max_price_per_gas)用户签名时需要指定两个值:
- —— 区块内交易优先级的小费
priority_price_per_gas - —— 总Gas价格的安全上限
max_price_per_gas
网络控制,该值对区块内所有交易一致。
base_price_per_gasBlock and Transaction Limits
区块与交易限制
| Parameter | Value |
|---|---|
| Block gas limit | 200M gas |
| Transaction gas limit | 30M gas |
| Minimum base fee | 100 MON-gwei (100 x 10^-9 MON) |
These are significantly higher than Ethereum's 30M block gas limit, which means Monad blocks can fit more transactions.
| 参数 | 数值 |
|---|---|
| 区块Gas上限 | 2亿Gas |
| 交易Gas上限 | 3000万Gas |
| 最低基础费用 | 100 MON-gwei(100 x 10^-9 MON) |
这些数值远高于Ethereum的3000万区块Gas上限,这意味着Monad区块可以容纳更多交易。
Base Fee Controller
基础费用控制器
Monad's base fee controller is different from Ethereum's. It increases more slowly and decreases more quickly to prevent blockspace underutilization from overpricing.
Controller parameters:
- max_step_size = 1/28
- target = 160M gas (80% of block capacity)
- beta = 0.96
- epsilon = 160M
The base fee updates each block using an exponential adjustment based on how full the block was relative to the target. The formula uses exponential smoothing (beta = 0.96) to track historical variance in block fullness, producing smoother fee transitions than Ethereum's simpler mechanism.
In practice, this means gas prices on Monad are more stable and recover faster after spikes.
Monad的基础费用控制器与Ethereum不同。它上涨更缓慢,下降更迅速,以避免因定价过高导致区块空间未被充分利用。
控制器参数:
- max_step_size = 1/28
- target = 1.6亿Gas(区块容量的80%)
- beta = 0.96
- epsilon = 1.6亿
基础费用会根据区块相对于目标的填充程度,通过指数调整机制在每个区块更新。该公式使用指数平滑(beta = 0.96)来跟踪区块填充率的历史变化,相比Ethereum的简单机制,能产生更平滑的费用过渡。
实际上,这意味着Monad上的Gas价格更稳定,并且在峰值后恢复更快。
Transaction Ordering
交易排序
The default Monad client orders transactions using a Priority Gas Auction, transactions are sorted by descending total gas price (base fee + priority fee).
默认的Monad客户端使用优先级Gas拍卖对交易排序,交易按总Gas价格(基础费用+优先级费用)降序排列。
Developer Guidelines
开发者指南
Always Set Explicit Gas Limits for Known Costs
为已知成本设置明确的Gas上限
For operations with fixed gas costs, set the gas limit explicitly before submitting to wallets:
typescript
// Good: explicit gas limit for a native transfer
const tx = {
to: recipient,
value: parseEther("1.0"),
gasLimit: 21000n,
};This is important because some wallets (like MetaMask) use to determine the gas limit. If that call reverts (e.g., the contract call would fail), the wallet may fall back to a very high gas limit. On Monad, the user would then pay for that entire inflated limit since gas is charged on the limit, not on actual usage.
eth_estimateGas对于固定Gas成本的操作,在提交给钱包前明确设置Gas上限:
typescript
// 推荐:为原生转账设置明确的Gas上限
const tx = {
to: recipient,
value: parseEther("1.0"),
gasLimit: 21000n,
};这一点很重要,因为部分钱包(如MetaMask)会使用来确定Gas上限。如果该调用失败(例如合约调用会报错),钱包可能会回退到一个非常高的Gas上限。在Monad上,用户将为整个虚高的上限付费,因为Gas是按上限收费,而非实际使用量。
eth_estimateGasGas Estimation in Frontend Code
前端代码中的Gas估算
When using viem or wagmi to estimate gas, remember that the estimate is what users will actually pay not a lower bound. Add only a small buffer if needed:
typescript
// If you must estimate, keep the buffer small
const estimate = await publicClient.estimateGas({ ... });
const gasLimit = estimate + (estimate / 10n); // 10% buffer at most当使用viem或wagmi估算Gas时,请记住估算值就是用户实际需要支付的费用,而非下限。如果需要,仅添加少量缓冲:
typescript
// 若必须估算,缓冲幅度要小
const estimate = await publicClient.estimateGas({ ... });
const gasLimit = estimate + (estimate / 10n); // 最多10%的缓冲Displaying Gas Costs to Users
向用户显示Gas成本
When showing gas costs in your UI, calculate from the gas limit (not "gas used" from receipts on other chains):
typescript
const gasCost = gasLimit * gasPrice;在UI中显示Gas成本时,请根据Gas上限计算(而非其他链上收据中的“实际消耗Gas”):
typescript
const gasCost = gasLimit * gasPrice;Smart Contract Considerations
智能合约注意事项
- Monad's 30M transaction gas limit is the same as Ethereum's block gas limit, so individual transactions can be very large.
- Optimize your contracts to use less gas on Monad this directly saves users money since they pay for the limit, and tighter estimates mean tighter limits.
- If your contract has functions with predictable gas costs, document them so frontends can set explicit limits.
- Monad的3000万交易Gas上限与Ethereum的区块Gas上限相同,因此单个交易可以非常大。
- 优化你的合约以在Monad上使用更少的Gas——这直接为用户节省资金,因为用户按上限付费,更精准的估算意味着更紧凑的上限。
- 如果你的合约有可预测Gas成本的函数,请记录下来,以便前端可以设置明确的上限。
Opcode Pricing Differences
操作码定价差异
Monad adjusts a few opcode prices upward rather than discounting everything. This achieves the same relative effect with minimal disruption. The changes reflect different resource scarcity in Monad's high-performance architecture, particularly for disk-based state operations.
Monad上调了部分操作码的价格而非全面降价。这在最小化干扰的同时达到了相同的相对效果。这些变化反映了Monad高性能架构中不同的资源稀缺性,尤其是基于磁盘的状态操作。
Cold State Access is Much More Expensive
冷状态访问成本更高
| Operation | Ethereum | Monad | Increase |
|---|---|---|---|
| Account access (cold) | 2,600 gas | 10,100 gas | +7,500 |
| Storage access (cold) | 2,100 gas | 8,100 gas | +6,000 |
| Account access (warm) | 100 gas | 100 gas | unchanged |
| Storage access (warm) | 100 gas | 100 gas | unchanged |
Affected opcodes:
- Account access: ,
BALANCE,EXTCODESIZE,EXTCODECOPY,EXTCODEHASH,CALL,CALLCODE,DELEGATECALL,STATICCALLSELFDESTRUCT - Storage access: ,
SLOADSSTORE
What this means for developers:
- Contracts that touch many cold storage slots or call many external contracts will cost significantly more on Monad.
- Warm access is identical to Ethereum, so accessing the same slot/account repeatedly within a transaction has no extra cost.
- Batch operations that access a storage slot once (cold) and then reuse it (warm) are fine. But patterns that do single cold reads across many different slots will be more expensive.
- If your contract reads from many different storage slots in a single call, the gas estimate will be higher on Monad. Account for this when setting gas limits.
| 操作 | Ethereum | Monad | 涨幅 |
|---|---|---|---|
| 账户访问(冷) | 2,600 Gas | 10,100 Gas | +7,500 |
| 存储访问(冷) | 2,100 Gas | 8,100 Gas | +6,000 |
| 账户访问(热) | 100 Gas | 100 Gas | 无变化 |
| 存储访问(热) | 100 Gas | 100 Gas | 无变化 |
受影响的操作码:
- 账户访问:、
BALANCE、EXTCODESIZE、EXTCODECOPY、EXTCODEHASH、CALL、CALLCODE、DELEGATECALL、STATICCALLSELFDESTRUCT - 存储访问:、
SLOADSSTORE
对开发者的意义:
- 涉及大量冷存储槽或调用大量外部合约的合约在Monad上的成本会显著更高。
- 热访问与Ethereum完全相同,因此在一笔交易中重复访问相同的存储槽/账户不会产生额外成本。
- 先访问一次存储槽(冷)然后重复使用(热)的批量操作是可行的。但对多个不同存储槽进行单次冷读取的模式会更昂贵。
- 如果你的合约在单次调用中读取多个不同的存储槽,Monad上的Gas估算会更高。设置Gas上限时要考虑到这一点。
Precompile Repricing
预编译合约重新定价
Cryptographic precompiles cost 2-5x more on Monad:
| Precompile | Address | Ethereum | Monad | Multiplier |
|---|---|---|---|---|
| ecRecover | 0x01 | 3,000 | 6,000 | 2x |
| ecAdd | 0x06 | 150 | 300 | 2x |
| ecMul | 0x07 | 6,000 | 30,000 | 5x |
| ecPairing | 0x08 | 45,000 | 225,000 | 5x |
| blake2f | 0x09 | rounds x 1 | rounds x 2 | 2x |
| point evaluation | 0x0a | 50,000 | 200,000 | 4x |
What this means for developers:
- Contracts relying heavily on signature verification () will use 2x the gas for those operations.
ecRecover - ZK-related operations (,
ecMul, point evaluation) are 4-5x more expensive. If your contract does on-chain ZK proof verification, gas estimates from Ethereum will be significantly off.ecPairing - Factor these higher precompile costs into gas limit calculations if your contract uses them.
加密预编译合约在Monad上的成本是Ethereum的2-5倍:
| 预编译合约 | 地址 | Ethereum | Monad | 倍数 |
|---|---|---|---|---|
| ecRecover | 0x01 | 3,000 | 6,000 | 2倍 |
| ecAdd | 0x06 | 150 | 300 | 2倍 |
| ecMul | 0x07 | 6,000 | 30,000 | 5倍 |
| ecPairing | 0x08 | 45,000 | 225,000 | 5倍 |
| blake2f | 0x09 | rounds x 1 | rounds x 2 | 2倍 |
| point evaluation | 0x0a | 50,000 | 200,000 | 4倍 |
对开发者的意义:
- 严重依赖签名验证()的合约,这些操作的Gas消耗会是原来的2倍。
ecRecover - ZK相关操作(、
ecMul、point evaluation)的成本是原来的4-5倍。如果你的合约在链上进行ZK证明验证,Ethereum上的Gas估算会严重偏离实际。ecPairing - 如果你的合约使用这些预编译合约,请将更高的成本纳入Gas上限计算。