Skip to content

getStorageAt

Returns the value from a storage slot at a given address.

Usage

example.ts
import { toHex } from 'viem'
import { wagmiAbi } from './abi'
import { publicClient } from './client'
 
const data = await publicClient.getStorageAt({
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  slot: toHex(0)
})

Return Value

Hex

The value of the storage slot.

Parameters

address

The contract address.

const data = await publicClient.getStorageAt({
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', 
  slot: toHex(0)
})

slot

The storage position (as a hex encoded value).

const data = await publicClient.getStorageAt({
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  slot: toHex(0) 
})

blockNumber (optional)

  • Type: number

The block number to perform the storage slot read against.

const bytecode = await publicClient.getStorageAt({
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  slot: toHex(0),
  blockNumber: 15121123n, 
})

blockTag (optional)

  • Type: 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'
  • Default: 'latest'

The block tag to perform the storage slot read against.

const bytecode = await publicClient.getStorageAt({
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  slot: toHex(0),
  blockTag: 'safe', 
})

JSON-RPC Method

eth_getStorageAt