Try it Live
Run MaxFeePerGas examples in the interactive playground
MaxFeePerGas
EIP-1559 maximum fee per gas representing the maximum total gas price a user is willing to pay for transaction inclusion. Must be >= baseFeePerGas + maxPriorityFeePerGas for transaction to be included.Overview
Branded bigint type representing max fee in Wei. Acts as a cap on total gas spending. Excess (maxFee - actualPrice) is refunded to sender.Quick Start
Type Definition
API
Construction
from(value)
Create from bigint, number, or hex string.
fromGwei(gwei)
Create from Gwei value.
fromWei(wei)
Create from Wei value (alias for from).
Conversion
toGwei(maxFee)
Convert to Gwei.
toWei(maxFee)
Convert to Wei (identity).
toNumber(maxFee)
Convert to number. Warning: precision loss on large values.
toBigInt(maxFee)
Convert to bigint (identity).
Comparison
equals(maxFee1, maxFee2)
Check equality.
compare(maxFee1, maxFee2)
Compare values. Returns -1, 0, or 1.
Fee Setting Strategies
Conservative
Set maxFee slightly above current base fee:Normal
Set maxFee with reasonable headroom:Aggressive
Set high maxFee for guaranteed inclusion:Real-world Examples
Transaction Submission
Fee Validation
Fee Estimation
Common Patterns
Fee Levels
Dynamic Adjustment
Refund Mechanics
Unused portion of maxFee is refunded:Related Types
- BaseFeePerGas - Network base fee
- MaxPriorityFeePerGas - Maximum tip
- EffectiveGasPrice - Actual price paid
Specification
- EIP-1559: Fee market change for ETH 1.0 chain
- Must satisfy:
maxFeePerGas >= baseFeePerGas + maxPriorityFeePerGas - Excess refunded to sender
- Values in Wei (1 Gwei = 10^9 Wei)

