> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# Estimate Fees \[fee.estimateFeesPerGas]

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

## Usage

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

:::code-group
```ts twoslash [example.ts]
import { client } from './viem.config'

const fees = await client.fee.estimateFeesPerGas()
// @log: {
// @log:   maxFeePerGas: 15040000000n,
// @log:   maxPriorityFeePerGas: 1000000000n,
// @log: }
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, http, publicActions } from 'viem'
import { mainnet } from 'viem/chains'

export const client = Client.create({
  chain: mainnet,
  transport: http(),
}).extend(publicActions())
```
:::

### Standalone Action

Call `Actions.fee.estimateFeesPerGas` directly by passing the Client as the first argument.

:::code-group
```ts twoslash [example.ts]
import { Actions } from 'viem'
import { client } from './viem.config'

const fees = await Actions.fee.estimateFeesPerGas(client)
// @log: {
// @log:   maxFeePerGas: 15040000000n,
// @log:   maxPriorityFeePerGas: 1000000000n,
// @log: }
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, http } from 'viem'
import { mainnet } from 'viem/chains'

export const client = Client.create({
  chain: mainnet,
  transport: http(),
})
```
:::

## Return Value

`{ gasPrice } | { maxFeePerGas, maxPriorityFeePerGas }`

An estimate (in wei) for the fees per gas. Returns `maxFeePerGas` and `maxPriorityFeePerGas` for the default `eip1559` type, or `gasPrice` for the `legacy` type.

## Parameters

### chain

* **Type:** `Chain`
* **Default:** `client.chain`

Overrides the chain used to derive fees (and any `chain.fees` configuration).

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet, optimism } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const fees = await Actions.fee.estimateFeesPerGas(client, {
  chain: optimism, // [!code focus]
})
```

### type

* **Type:** `'legacy' | 'eip1559'`
* **Default:** `'eip1559'`

The type of fee values to return.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const { gasPrice } = await Actions.fee.estimateFeesPerGas(client, {
  type: 'legacy', // [!code focus]
})
```

## Errors

| Error | Description |
| --- | --- |
| `Actions.fee.Errors.BaseFeeScalarError` | The chain's `baseFeeMultiplier` resolved to a value less than `1`. |
| `Actions.fee.Errors.Eip1559FeesNotSupportedError` | The chain does not support EIP-1559 fees (no `baseFeePerGas` on the latest block). |
