Skip to content
On this page

setStorageAt โ€‹

Writes to a slot of an account's storage.

Usage โ€‹

ts
import { testClient } from './client'

await testClient.setStorageAt({ 
  address: '0xe846c6fcf817734ca4527b28ccb4aea2b6663c79',
  index: 2,
  value: '0x0000000000000000000000000000000000000000000000000000000000000069'
})
ts
import { createTestClient, http } from 'viem'
import { foundry } from 'viem/chains'

export const testClient = createTestClient({
  chain: foundry,
  mode: 'anvil',
  transport: http(), 
})

Parameters โ€‹

address โ€‹

The account address.

ts
await testClient.setStorageAt({
  address: '0xe846c6fcf817734ca4527b28ccb4aea2b6663c79', 
  index: 2,
  value: '0x0000000000000000000000000000000000000000000000000000000000000069'
})

index โ€‹

  • Type: number | Hash

The storage slot (index). Can either be a number or hash value.

ts
await testClient.setStorageAt({
  address: '0xe846c6fcf817734ca4527b28ccb4aea2b6663c79',
  index: '0xa6eef7e35abe7026729641147f7915573c7e97b47efa546f5f6e3230263bcb49', 
  value: '0x0000000000000000000000000000000000000000000000000000000000000069'
})

value โ€‹

  • Type: number

The value to store as a 32 byte hex string.

ts
await testClient.setStorageAt({
  address: '0xe846c6fcf817734ca4527b28ccb4aea2b6663c79',
  index: 2,
  value: '0x0000000000000000000000000000000000000000000000000000000000000069' 
})

Released under the MIT License.