Skip to content
LogoLogo

estimateFeesPerGas

Returns an estimate for the fees per gas (in wei) for a transaction to be likely included in the next block.

If chain.fees.estimateFeesPerGas is set on the Client Chain or override Chain, it will use the returned value.

Otherwise, for EIP-1559 Transactions, viem will estimate the fees using a combination of the block's base fee per gas (to derive maxFeePerGas) + the estimateMaxPriorityFeePerGas Action (to derive maxPriorityFeePerGas). For Legacy Transactions, viem will estimate the fee based on the gas price (via the getGasPrice Action).

Usage

import {  } from './client'
 
const {
  ,
  
} = await .()
}
const { } = await .({ : 'legacy' })
{ gasPrice: 15_000_000_000n }

Returns

FeeValues

An estimate (in wei) for the fees per gas.

Parameters

chain (optional)

Optional Chain override. Used to infer the fees per gas from chain.fees.estimateFeesPerGas.

import {  } from 'viem/chains'
 
const { ,  } = 
  await .({
    :  
  })

type (optional)

  • Type: "legacy" | "eip1559"
  • Default: "eip1559"
const {  } = await .({
  : 'legacy'
})