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

# Set Nonce \[address.setNonce]

Modifies (overrides) the nonce of an account.

## Usage

This example modifies (overrides) the nonce of an account.

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

await client.address.setNonce({
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  nonce: 420,
})
```

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

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

### Standalone Action

Call `Actions.address.setNonce` directly by passing the Client as the first argument.

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

await Actions.address.setNonce(client, {
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  nonce: 420,
})
```

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

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

## Recipes

### Advance the Current Nonce

Read the current nonce, then set the next value.

```ts twoslash
import { Client, http, publicActions, testActions } from 'viem'
import { anvil } from 'viem/chains'

const client = Client.create({
  chain: anvil,
  transport: http(),
})
  .extend(publicActions())
  .extend(testActions())

const address = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
const nonce = await client.address.getTransactionCount({ address })

await client.address.setNonce({
  address,
  nonce: nonce + 1, // [!code focus]
})
```

## Return Value

`void`

No value is returned.

## Parameters

### address

* **Type:** `Address`

The account address.

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

const client = Client.create({
  chain: mainnet,
  transport: http(),
})
// ---cut---
await Actions.address.setNonce(client, {
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', // [!code focus]
  nonce: 420,
  mode: 'hardhat',
})
```

### mode

* **Type:** `'anvil' | 'hardhat' | 'ganache'`
* **Default:** `'anvil'`

The test node implementation to target.

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

const client = Client.create({
  chain: mainnet,
  transport: http(),
})
// ---cut---
await Actions.address.setNonce(client, {
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  nonce: 420,
  mode: 'hardhat', // [!code focus]
})
```

### nonce

* **Type:** `number`

The nonce to set.

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

const client = Client.create({
  chain: mainnet,
  transport: http(),
})
// ---cut---
await Actions.address.setNonce(client, {
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  nonce: 420, // [!code focus]
  mode: 'hardhat',
})
```
