Skip to main content

Try it Live

Run FeeMarket examples in the interactive playground

FeeMarket Utilities

Validation and conversion utilities.

Validation

validateTxFeeParams

Validate transaction fee parameters. Returns empty array if valid, array of error messages if invalid. Parameters:
  • params - Transaction or blob transaction fee parameters
Returns: Array of validation error messages (empty if valid) Validates: Regular tx (TxFeeParams):
  • maxFeePerGas >= 0
  • maxPriorityFeePerGas >= 0
  • maxPriorityFeePerGas <= maxFeePerGas
  • baseFee >= 0
Blob tx (BlobTxFeeParams), additionally:
  • maxFeePerBlobGas >= 0
  • blobBaseFee >= 0
  • 1 <= blobCount <= 6
Examples:
Usage Pattern:

validateState

Validate block fee market state. Returns empty array if valid, array of error messages if invalid. Parameters:
  • state - Block fee market state
Returns: Array of validation error messages (empty if valid) Validates:
  • gasUsed >= 0
  • gasLimit > 0
  • gasUsed <= gasLimit
  • baseFee >= MIN_BASE_FEE (7 wei)
  • excessBlobGas >= 0
  • blobGasUsed >= 0
  • blobGasUsed <= MAX_BLOB_GAS_PER_BLOCK (786432)
Examples:
Usage Pattern:

Conversion

weiToGwei

Convert wei to gwei for human-readable display. Parameters:
  • wei - Amount in wei
Returns: String formatted to 9 decimal places Examples:
Display Usage:
Precision: 9 decimal places (1 gwei = 10^9 wei). All wei values represented.

gweiToWei

Convert gwei to wei. Parameters:
  • gwei - Amount in gwei (JavaScript number)
Returns: Amount in wei (bigint) Examples:
Precision: Floors fractional wei (rounds down).
Usage:

Combined Usage

Validate and Display

State Validation Pipeline

User Input Validation

Implementation

Locations:
  • BrandedFeeMarket/validateTxFeeParams.js
  • BrandedFeeMarket/validateState.js
  • BrandedFeeMarket/weiToGwei.js
  • BrandedFeeMarket/gweiToWei.js
See branded-feemarket.mdx for implementation details.

References