Overview
FeeMarket implements Ethereum’s dynamic fee mechanisms: EIP-1559 for base fees and EIP-4844 for blob fees. Use it to calculate next block fees, validate transactions, project fee trends, and estimate costs.Types
State
Complete fee market state for a block:TxFeeParams
Transaction fee parameters for EIP-1559:BlobTxFeeParams
Extended parameters for blob transactions (EIP-4844):TxFee
Calculated transaction fee breakdown:BlobTxFee
Extended fee breakdown for blob transactions:EIP-1559 Methods
BaseFee
Calculate next block’s base fee using the EIP-1559 formula.gasTarget = gasLimit / 2- If
gasUsed > gasTarget: base fee increases (up to 12.5%) - If
gasUsed < gasTarget: base fee decreases (up to 12.5%) - If
gasUsed == gasTarget: base fee unchanged - Minimum base fee: 7 wei
calculateTxFee
Calculate effective transaction fee breakdown.effectiveGasPrice = min(maxFeePerGas, baseFee + maxPriorityFeePerGas)priorityFee = effectiveGasPrice - baseFee
canIncludeTx
Check if transaction meets minimum fee requirements.maxFeePerBlobGas >= blobBaseFee.
validateTxFeeParams
Validate transaction fee parameters.maxFeePerGas >= 0maxPriorityFeePerGas >= 0maxPriorityFeePerGas <= maxFeePerGasbaseFee >= 0- For blob txs:
blobCountbetween 1 and 6
EIP-4844 Methods
BlobBaseFee
Calculate blob base fee using EIP-4844 exponential formula.MIN_BLOB_BASE_FEE * e^(excessBlobGas / UPDATE_FRACTION)
calculateExcessBlobGas
Calculate excess blob gas for next block.max(0, parentExcess + parentBlobGasUsed - TARGET_BLOB_GAS_PER_BLOCK)
calculateBlobTxFee
Calculate complete blob transaction fee breakdown.State Methods
nextState
Calculate next block’s complete fee market state.validateState
Validate block state parameters.gasUsed >= 0and<= gasLimitgasLimit > 0baseFee >= MIN_BASE_FEE(7 wei)excessBlobGas >= 0blobGasUsed >= 0and<= MAX_BLOB_GAS_PER_BLOCK
projectBaseFees
Project base fees over multiple blocks.Utility Functions
gweiToWei
Convert gwei to wei.weiToGwei
Convert wei to gwei for display.Constants
EIP-1559 Constants
EIP-4844 Constants
Usage Examples
Estimate Transaction Cost
Monitor Fee Trends
Validate Before Submission
Related
- Gas - Gas limits and usage
- Transaction - Transaction types
- KZG - Blob commitment cryptography
- EIP-1559 - Fee market specification
- EIP-4844 - Blob transaction specification

