Try it Live
Run FeeMarket examples in the interactive playground
Fee Market Calculations
Transaction fee calculations and state transitions.calculateTxFee
params.maxFeePerGas- Maximum fee per gas (wei)params.maxPriorityFeePerGas- Maximum priority fee/tip (wei)params.baseFee- Current block base fee (wei)
TxFee with effectiveGasPrice, priorityFee, baseFee
Formula:
calculateBlobTxFee
params.maxFeePerGas- Maximum fee per gas (wei)params.maxPriorityFeePerGas- Maximum priority fee (wei)params.baseFee- Current block base fee (wei)params.maxFeePerBlobGas- Maximum blob gas fee (wei)params.blobBaseFee- Current blob base fee (wei)params.blobCount- Number of blobs (1-6)
BlobTxFee extending TxFee with blobGasPrice, totalBlobFee
Formula:
canIncludeTx
params- Transaction or blob transaction fee parameters
true if transaction can be included
Validation:
- Regular tx:
maxFeePerGas >= baseFee - Blob tx: Above +
maxFeePerBlobGas >= blobBaseFee
nextState
state- Current block state
baseFee- Calculated via BaseFeeexcessBlobGas- Calculated via calculateExcessBlobGasgasUsed- Reset to 0blobGasUsed- Reset to 0gasLimit- Unchanged
projectBaseFees
initialState- Starting stateblocks- Number of blocks to projectavgGasUsed- Average gas used per blockavgBlobGasUsed- Average blob gas per block (optional, default 0)
State Convenience Methods
State namespace provides this:-bound convenience methods:
Implementation
Locations:BrandedFeeMarket/calculateTxFee.jsBrandedFeeMarket/calculateBlobTxFee.jsBrandedFeeMarket/canIncludeTx.jsBrandedFeeMarket/nextState.jsBrandedFeeMarket/projectBaseFees.js

