List bigmaps
import (
"github.com/trilitech/tzgo/micheline"
"github.com/trilitech/tzgo/rpc"
"github.com/trilitech/tzgo/tezos"
)
// we use the hic et nunc NFT market on mainnet as example
addr := tezos.MustParseAddress("KT1Hkg5qeNhfwpKW4fXvq7HGZB9z2EnmCCA9")
// init RPC client
c, _ := rpc.NewClient("https://rpc.tzpro.io", nil)
// fetch the contract's script and most recent storage
script, _ := c.GetContractScript(ctx, addr)
// bigmap pointers as []int64
ids := script.BigmapsById()
// bigmap pointers as named map[string]int64 (names from type annotations)
named := script.BigmapsByName()
Fetch and decode bigmap values
// init RPC client
c, _ := rpc.NewClient("https://rpc.tzpro.io", nil)
// load bigmap type info (use the Baker Registry on mainnet as example)
biginfo, _ := c.GetBigmapInfo(ctx, 17)
// list all bigmap keys
bigkeys, _ := c.GetBigmapKeys(ctx, 17)
// visit each value
for _, key := range bigkeys {
bigval, _ := c.GetBigmapValue(ctx, 17, key)
// unfold Micheline type into human readable form
val := micheline.NewValue(micheline.NewType(biginfo.ValueType), bigval)
m, _ := val.Map()
buf, _ := json.MarshalIndent(m, "", " ")
fmt.Println(string(buf))
}