> **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 Storage \[address.setStorageAt]

Writes to a slot of an account's storage.

## Usage

This example writes to a slot of an account's storage.

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

await client.address.setStorageAt({
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  index: 2,
  value: '0x0000000000000000000000000000000000000000000000000000000000000045',
})
```

```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.setStorageAt` 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.setStorageAt(client, {
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  index: 2,
  value: '0x0000000000000000000000000000000000000000000000000000000000000045',
})
```

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

### Set a Mapping Entry

For a Solidity mapping declared at slot `0`, hash the encoded key and slot to derive its storage index.

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

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

const account = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
const index = Hash.keccak256( // [!code focus]
  AbiParameters.encode( // [!code focus]
    AbiParameters.from('address, uint256'), // [!code focus]
    [account, 0n], // [!code focus]
  ), // [!code focus]
) // [!code focus]

await client.address.setStorageAt({
  address: '0xe846c6fcf817734ca4527b28ccb4aea2b6663c79',
  index, // [!code focus]
  value: '0x0000000000000000000000000000000000000000000000000000000000000001', // [!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.setStorageAt(client, {
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', // [!code focus]
  index: 2,
  value: '0x0000000000000000000000000000000000000000000000000000000000000045',
  mode: 'hardhat',
})
```

### index

* **Type:** `number | Hex`

The storage slot (index). Either a number or a hash value.

```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.setStorageAt(client, {
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  index: 2, // [!code focus]
  value: '0x0000000000000000000000000000000000000000000000000000000000000045',
  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.setStorageAt(client, {
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  index: 2,
  value: '0x0000000000000000000000000000000000000000000000000000000000000045',
  mode: 'hardhat', // [!code focus]
})
```

### value

* **Type:** `Hex`

The value to store, as a 32-byte hex string.

```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.setStorageAt(client, {
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  index: 2,
  value: '0x0000000000000000000000000000000000000000000000000000000000000045', // [!code focus]
  mode: 'hardhat',
})
```
