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

# Execute Calls \[erc7821.execute]

Executes calls using the `execute` function on an [ERC-7821-compatible contract](https://eips.ethereum.org/EIPS/eip-7821).

Before sending, Viem checks the requested mode with
[`Actions.erc7821.supportsExecutionMode`](/docs/actions/erc7821/supportsExecutionMode).
Viem then encodes the calls and broadcasts them with
[`Actions.transaction.send`](/docs/actions/wallet/transaction/send).

## Usage

This example executes call(s) using the `execute` function on an [ERC-7821-compatible contract](https://eips.ethereum.org/EIPS/eip-7821).

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

const hash = await client.erc7821.execute({
  address: client.account.address,
  calls: [
    { data: '0xdeadbeef', to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' },
    { to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', value: 69420n },
  ],
})
// @log: '0x9d2478f5cb1d21ac4153dbe5da9700e106a06d1cf1b957554fcd51de26eec4ae'
```

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

export const client = Client.create({
  account: Account.fromPrivateKey('0x...'),
  chain: mainnet,
  transport: http(),
}).extend(erc7821Actions())
```
:::

### Standalone Action

Call `Actions.erc7821.execute` 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 hash = await Actions.erc7821.execute(client, {
  address: client.account.address,
  calls: [
    { data: '0xdeadbeef', to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' },
    { to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', value: 69420n },
  ],
})
// @log: '0x9d2478f5cb1d21ac4153dbe5da9700e106a06d1cf1b957554fcd51de26eec4ae'
```

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

export const client = Client.create({
  account: Account.fromPrivateKey('0x...'),
  chain: mainnet,
  transport: http(),
})
```
:::

Calls can also be defined by contract function parameters (`abi`, `functionName`, `args`):

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

const hash = await Actions.erc7821.execute(client, {
  address: client.account.address,
  calls: [
    {
      abi: Abi.from(['function mint(uint256 amount)']), // [!code focus]
      args: [69420n], // [!code focus]
      functionName: 'mint', // [!code focus]
      to: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', // [!code focus]
    },
  ],
})
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
// [!include ~/snippets/docs/viem.config.ts:setup]
```
:::

## Recipes

### Execute a Contract Function

Provide an ABI and function name to encode a contract call without preparing calldata separately.

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

const hash = await client.erc7821.execute({
  address: client.account.address,
  calls: [ // [!code focus]
    { // [!code focus]
      abi: Abi.from(['function mint()']), // [!code focus]
      functionName: 'mint', // [!code focus]
      to: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', // [!code focus]
    }, // [!code focus]
  ], // [!code focus]
})
```

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

export const client = Client.create({
  account: Account.fromPrivateKey('0x...'),
  chain: mainnet,
  transport: http(),
}).extend(erc7821Actions())
```
:::

### Include Operation Data

Pass `opData` when the ERC-7821 contract needs signatures, paymaster context, or other operation
metadata. Viem checks support for the `opData` mode first.

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

export function executeWithData(opData: Hex.Hex) {
  return client.erc7821.execute({
    address: client.account.address,
    calls: [
      {
        to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
        value: 1n,
      },
    ],
    opData, // [!code focus]
  })
}
```

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

export const client = Client.create({
  account: Account.fromPrivateKey('0x...'),
  chain: mainnet,
  transport: http(),
}).extend(erc7821Actions())
```
:::

### Execute Without a Client Account

Pass `account` when the Client does not define the transaction sender. The execution `address`
remains the ERC-7821-compatible contract.

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

const account = Account.fromPrivateKey('0x...')

const hash = await client.erc7821.execute({
  account, // [!code focus]
  address: account.address,
  calls: [
    {
      to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
      value: 1n,
    },
  ],
})
```

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

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

## Return Value

`Hex`

The transaction hash. Wait for inclusion with [`Actions.transaction.waitForReceipt`](/docs/actions/public/transaction/waitForReceipt).

## Parameters

Also accepts the remaining
[`Actions.transaction.send` options](/docs/actions/wallet/transaction/send#parameters), including
`authorizationList`, `nonce`, and fee options.

### account

* **Type:** `Account | Address`
* **Default:** `client.account`

The Account sending the transaction.

```ts twoslash
import { Account, Actions } from 'viem'
// [!include ~/snippets/docs/reference-client.ts:setup]
// ---cut---
const account = Account.fromPrivateKey('0x...')

const hash = await Actions.erc7821.execute(client, {
  account, // [!code focus]
  address: account.address,
  calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', value: 1n }],
})
```

### address

* **Type:** `Address`

The address of the ERC-7821-compatible contract that executes the calls (for example, a delegated account).

```ts twoslash
import { Actions } from 'viem'
// [!include ~/snippets/docs/reference-client.ts:setup]
// ---cut---
const hash = await Actions.erc7821.execute(client, {
  address: client.account.address, // [!code focus]
  calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', value: 1n }],
})
```

### calls

* **Type:** `Call[]`

The calls to execute. Each call is either raw call data (`to`, `data`, `value`) or contract function parameters (`abi`, `functionName`, `args`).

```ts twoslash
import { Actions } from 'viem'
// [!include ~/snippets/docs/reference-client.ts:setup]
// ---cut---
const hash = await Actions.erc7821.execute(client, {
  address: client.account.address,
  calls: [ // [!code focus]
    { data: '0xdeadbeef', to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }, // [!code focus]
    { to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', value: 69420n }, // [!code focus]
  ], // [!code focus]
})
```

### opData

* **Type:** `Hex`

Additional data to include for execution (for example, signatures or paymaster context). When provided, the calls are encoded with the `opData` execution mode.

```ts twoslash
import { Actions } from 'viem'
// [!include ~/snippets/docs/reference-client.ts:setup]
// ---cut---
const hash = await Actions.erc7821.execute(client, {
  address: client.account.address,
  calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', value: 1n }],
  opData: '0xdeadbeef', // [!code focus]
})
```

## Errors

| Error | Description |
| --- | --- |
| `Actions.erc7821.Errors.ExecuteUnsupportedError` | The target contract does not support ERC-7821 execution (or the requested mode). |
| `ContractError.ContractFunctionExecutionError` | A call reverted while executing the batch. |
