> **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.

# `l2.estimateContractTotalFee`

Encodes a contract write and estimates its L1 data fee, L2 execution fee, and operator fee.

## Usage

Estimate every fee component for an ERC-20 transfer.

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

const fee = await client.fee.estimateContractTotalFee({ // [!code focus:9]
  abi: Abis.erc20,
  address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
  args: [
    '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    Value.from('1', 6),
  ],
  functionName: 'transfer',
})
// @log: 2441018000000n
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
// [!include ~/snippets/op-stack/l2.config.ts:setup]
```
:::

:::warning
This action requires an Isthmus-compatible `GasPriceOracle.getOperatorFee` implementation. Older deployments reject instead of returning a guessed zero fee.
:::

### Standalone Action

Call `Actions.l2.estimateContractTotalFee` directly by passing the Client as the first argument.

:::code-group
```ts twoslash [example.ts]
import { Actions } from 'viem/op-stack'
import { Abis, Value } from 'viem/utils'
import { client } from './viem.config'

const fee = await Actions.l2.estimateContractTotalFee(client, { // [!code focus:9]
  abi: Abis.erc20,
  address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
  args: [
    '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    Value.from('1', 6),
  ],
  functionName: 'transfer',
})
// @log: 2441018000000n
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
// [!include ~/snippets/op-stack/l2.config.ts:setup]
```
:::

## Return Value

`bigint`

The combined L1 data, L2 execution, and operator fee in wei.

## Parameters

### abi

* **Type:** `Abi`

The contract ABI used to encode the function call.

### accessList

* **Type:** `AccessList`

The EIP-2930 access list included in the transaction.

### account

* **Type:** `Account | Address`

The Account or address used as the transaction sender during estimation.

### address

* **Type:** `Address`

The contract address.

### args

* **Type:** `inferred from abi`

The positional arguments passed to the contract function.

### chain

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

The L2 Chain used to resolve transaction and oracle defaults.

### chainId

* **Type:** `number`
* **Default:** `chain.id`

The transaction Chain ID.

### functionName

* **Type:** `string`

The payable or nonpayable function selected from the ABI.

### gas

* **Type:** `bigint`

The transaction gas limit.

### gasPriceOracleAddress

* **Type:** `Address`

An override for the OP Stack gas price oracle address.

### maxFeePerGas

* **Type:** `bigint`

The maximum total fee per gas in wei.

### maxPriorityFeePerGas

* **Type:** `bigint`

The maximum priority fee per gas in wei.

### nonce

* **Type:** `number`

The transaction nonce.

### type

* **Type:** `'eip1559'`

The transaction envelope type.

### value

* **Type:** `bigint`

The native value in wei sent to a payable function.
