getStorageAt
Returns the value from a storage slot at a given address
Import
Import the public actions package so you can call this action.
import "github.com/ChefBingbong/viem-go/actions/public"Usage
A minimal example showing how to construct a public client and call this action.
import ( "context" "log"
"github.com/ethereum/go-ethereum/common" "github.com/ChefBingbong/viem-go/actions/public" "github.com/ChefBingbong/viem-go/client" "github.com/ChefBingbong/viem-go/client/transport" "github.com/ChefBingbong/viem-go/chain/definitions")
ctx := context.Background()
publicClient, err := client.CreatePublicClient(client.PublicClientConfig{ Chain: definitions.Mainnet, Transport: transport.HTTP("https://eth.llamarpc.com"),})if err != nil { log.Fatal(err)}defer func() { _ = publicClient.Close() }()
value, err := public.GetStorageAt(ctx, publicClient, public.GetStorageAtParameters{ Address: common.HexToAddress("0xA0Cf798816D4b9b9866b5330EEa46a18382f251e"), Slot: common.HexToHash("0x0"),})if err != nil { log.Fatal(err)}log.Printf("Storage value: %x", value)Returns
[]byte
The raw 32-byte storage value. Returns nil if the storage slot is zero/empty.
Parameters
Configuration options accepted by this action.
Address
- Type:
common.Address - Required
The contract/account address to read storage from.
import ( "github.com/ethereum/go-ethereum/common" "github.com/ChefBingbong/viem-go/actions/public")
value, err := public.GetStorageAt(ctx, publicClient, public.GetStorageAtParameters{ Address: common.HexToAddress("0xA0Cf798816D4b9b9866b5330EEa46a18382f251e"), Slot: common.HexToHash("0x0"),})Slot
- Type:
common.Hash - Required
The 32-byte storage slot key.
import ( "github.com/ethereum/go-ethereum/common" "github.com/ChefBingbong/viem-go/actions/public")
value, err := public.GetStorageAt(ctx, publicClient, public.GetStorageAtParameters{ Address: common.HexToAddress("0xA0Cf798816D4b9b9866b5330EEa46a18382f251e"), Slot: common.HexToHash("0x0"),})BlockNumber
- Type:
*uint64 - Optional
The block number to read the storage at.
import "github.com/ChefBingbong/viem-go/actions/public"
blockNum := uint64(12345)value, err := public.GetStorageAt(ctx, publicClient, public.GetStorageAtParameters{ Address: common.HexToAddress("0xA0Cf798816D4b9b9866b5330EEa46a18382f251e"), Slot: common.HexToHash("0x0"), BlockNumber: &blockNum,})BlockTag
- Type:
BlockTag - Default:
"latest" - Optional
The block tag to read the storage at (e.g., "latest", "pending").
import "github.com/ChefBingbong/viem-go/actions/public"
value, err := public.GetStorageAt(ctx, publicClient, public.GetStorageAtParameters{ Address: common.HexToAddress("0xA0Cf798816D4b9b9866b5330EEa46a18382f251e"), Slot: common.HexToHash("0x0"), BlockTag: public.BlockTagSafe,})JSON-RPC Method
Underlying JSON-RPC method used by this action.