> **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 Bytecode \[address.setCode]

Modifies the bytecode stored at an account's address.

## Usage

This example modifies the bytecode stored at an account's address.

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

await client.address.setCode({
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  bytecode: '0x60806040',
})
```

```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.setCode` 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.setCode(client, {
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  bytecode: '0x60806040',
})
```

```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

### Clear Account Bytecode

Set `bytecode` to `0x` to remove the code stored at an address.

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

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

await client.address.setCode({
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  bytecode: '0x', // [!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.setCode(client, {
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', // [!code focus]
  bytecode: '0x60806040',
  mode: 'hardhat',
})
```

### bytecode

* **Type:** `Hex`

The bytecode 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.setCode(client, {
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  bytecode: '0x60806040', // [!code focus]
  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.setCode(client, {
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  bytecode: '0x60806040',
  mode: 'hardhat', // [!code focus]
})
```
