Skip to main content

Try it Live

Run FeeMarket examples in the interactive playground

Fee Market Calculations

Transaction fee calculations and state transitions.

calculateTxFee

Calculate EIP-1559 transaction fee breakdown. Parameters:
  • params.maxFeePerGas - Maximum fee per gas (wei)
  • params.maxPriorityFeePerGas - Maximum priority fee/tip (wei)
  • params.baseFee - Current block base fee (wei)
Returns: TxFee with effectiveGasPrice, priorityFee, baseFee Formula:
Examples:
Total Cost:

calculateBlobTxFee

Calculate blob transaction fee (EIP-4844). Combines regular gas fee with blob gas fee. Parameters:
  • 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)
Returns: BlobTxFee extending TxFee with blobGasPrice, totalBlobFee Formula:
Examples:
Total Cost:

canIncludeTx

Check if transaction meets minimum fee requirements for inclusion. Parameters:
  • params - Transaction or blob transaction fee parameters
Returns: true if transaction can be included Validation:
  • Regular tx: maxFeePerGas >= baseFee
  • Blob tx: Above + maxFeePerBlobGas >= blobBaseFee
Examples:
Usage:

nextState

Calculate next block’s complete fee market state. Parameters:
  • state - Current block state
Returns: Next block’s state with updated fees and reset usage Updates:
  • baseFee - Calculated via BaseFee
  • excessBlobGas - Calculated via calculateExcessBlobGas
  • gasUsed - Reset to 0
  • blobGasUsed - Reset to 0
  • gasLimit - Unchanged
Examples:
State method:
Multi-block projection:

projectBaseFees

Project future base fees over multiple blocks with constant utilization. Parameters:
  • initialState - Starting state
  • blocks - Number of blocks to project
  • avgGasUsed - Average gas used per block
  • avgBlobGasUsed - Average blob gas per block (optional, default 0)
Returns: Array of projected base fees (length = blocks) Examples:
Projection Analysis:
Setting Transaction Fees:

State Convenience Methods

State namespace provides this:-bound convenience methods:
See types.mdx and FeeMarket.js for details.

Implementation

Locations:
  • BrandedFeeMarket/calculateTxFee.js
  • BrandedFeeMarket/calculateBlobTxFee.js
  • BrandedFeeMarket/canIncludeTx.js
  • BrandedFeeMarket/nextState.js
  • BrandedFeeMarket/projectBaseFees.js
See branded-feemarket.mdx for implementation details.

References