getStorageAt
Returns the value from a storage slot at a given address
Loading...
Returns the value from a storage slot at a given address
Import the public actions package so you can call this action.
import "github.com/ChefBingbong/viem-go/actions/public"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)[]byte
The raw 32-byte storage value. Returns nil if the storage slot is zero/empty.
Configuration options accepted by this action.
common.AddressThe 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"),})common.HashThe 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"),})*uint64The 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"latest"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,})Underlying JSON-RPC method used by this action.