Skip to main content
import * as FeeMarket from 'voltaire-effect/FeeMarket'
import { Effect } from 'effect'

// Create fee market state
const state = Effect.runSync(FeeMarket.from({
  gasUsed: 15000000n,
  gasLimit: 30000000n,
  baseFee: 1000000000n,
  excessBlobGas: 0n,
  blobGasUsed: 0n
}))

// Calculate next block's base fee
const nextBase = FeeMarket.BaseFee(15000000n, 30000000n, 1000000000n)

// Calculate blob base fee (EIP-4844)
const blobFee = FeeMarket.BlobBaseFee(393216n)

// Check if tx can be included
const ok = FeeMarket.canIncludeTx(2000000000n, 1000000000n) // maxFee > baseFee

// Compute next state
const next = FeeMarket.nextState(state)

API

FunctionDescription
from(input)Create fee market state
BaseFee(gasUsed, gasLimit, baseFee)Next block base fee
BlobBaseFee(excessBlobGas)Blob base fee
calculateTxFee(gas, price)Transaction fee
canIncludeTx(maxFee, baseFee)Inclusion check
nextState(state)Compute next state
weiToGwei(wei) / gweiToWei(gwei)Unit conversion

Constants

FeeMarket.Eip1559.ELASTICITY_MULTIPLIER         // 2n
FeeMarket.Eip1559.BASE_FEE_MAX_CHANGE_DENOMINATOR // 8n
FeeMarket.Eip4844.TARGET_BLOB_GAS_PER_BLOCK     // 393216n
FeeMarket.Eip4844.MAX_BLOB_GAS_PER_BLOCK        // 786432n