Skip to main content
TypeScript-first: In Zig, build payloads with std.json and POST via std.http.Client. Parse hex quantities before math.

Fee Methods

The eth namespace provides 4 methods for querying gas prices and fee history to estimate transaction costs.

Overview

Access fee methods directly on the provider:
// {"method":"eth_gasPrice","params":[]}
// {"method":"eth_maxPriorityFeePerGas","params":[]}
// {"method":"eth_feeHistory","params":["0xA","latest",[25,50,75]]}

Usage Patterns

Estimate Transaction Costs

Calculate gas costs for legacy transactions:
// total_cost = gasPriceWei * 21000n

Calculate EIP-1559 Fees

Build EIP-1559 transaction fees with historical data:
// maxFeePerGas = baseFee*2 + maxPriorityFee; parse hex strings to bigints first

Monitor Gas Prices

Track fee trends over time:
// Compute average of last N baseFeePerGas entries after parsing hex to bigint

Methods

eth_gasPrice

Get current gas price in wei.
// {"method":"eth_gasPrice","params":[]} → hex quantity
Returns: Current gas price in wei as a Quantity. Use Case: Legacy (non-EIP-1559) transaction fee estimation.

eth_maxPriorityFeePerGas

Get current max priority fee per gas (EIP-1559).
// {"method":"eth_maxPriorityFeePerGas","params":[]} → hex quantity
Returns: Suggested max priority fee per gas in wei as a Quantity. Use Case: EIP-1559 transaction fee calculation. This is the “tip” paid to validators.
For EIP-1559 transactions, set maxFeePerGas to at least baseFee + maxPriorityFeePerGas to ensure inclusion.

eth_feeHistory

Get historical gas fee data for a range of blocks.
// {"method":"eth_feeHistory","params":["0xA","latest",[25,50,75]]}
Parameters:
  • blockCount: Quantity - Number of blocks to query (max varies by node)
  • newestBlock: BlockTag | Quantity - Highest block to query
  • rewardPercentiles?: number[] - Priority fee percentiles (0-100)
Returns: FeeHistory object containing:
  • oldestBlock: Quantity - First block in range
  • baseFeePerGas: Quantity[] - Base fee per block
  • gasUsedRatio: number[] - Fraction of gas limit used
  • reward?: Quantity[][] - Priority fees at requested percentiles
Use Case: Analyze fee trends, predict optimal gas prices, calculate EIP-1559 fees with historical context.
The rewardPercentiles parameter is only applicable for EIP-1559 blocks. For pre-EIP-1559 blocks, the reward field will be empty.

eth_blobBaseFee

Get current blob base fee for EIP-4844 transactions.
// {"method":"eth_blobBaseFee","params":[]} → hex quantity
Returns: Current blob base fee in wei as a Quantity. Use Case: Calculate costs for EIP-4844 blob transactions. Blob fees are separate from execution gas fees.
This method is only available on networks that have activated EIP-4844 (Cancun upgrade). It will error on pre-Cancun networks.