How do you discover the indexes of the big maps of a contract? It seems you would have to inspect the storage, and correlate with the type of the storage, and pick out the numbers that correspond to big_maps. Not so fun to do programmatically.
The tezos-client and tezos-node RPC have no such feature.
If you don't mind using an API other then the node RPC you can find this in the new version of the tzstats indexer (GET /explorer/contract/{hash} returns an object with a key bigmap_ids which is an array) see https://api.babylonnet.tzstats.com/explorer/contract/KT1E5toJrALhVPuKpHWTbRVjgEvWWR98sVKj for an example, the id is also part of the decoded/unboxed storage endpoint at https://api.babylonnet.tzstats.com/explorer/contract/KT1E5toJrALhVPuKpHWTbRVjgEvWWR98sVKj/storage
If you are using the RPC you have to query all the block ids since the origination of the contract and collect the big_map_diff
's from the contract's applied transactions. This is a slow process so you will need to store this data. This amounts to building an indexer around the contract.
The internal structure form the block RPC looks like this:
"big_map_diff"?:
[ { /* update */
"action": "update",
"big_map": $bignum,
"key_hash": $script_expr,
"key": $micheline.007-PsDELPH1.michelson_v1.expression,
"value"?: $micheline.007-PsDELPH1.michelson_v1.expression }
|| { /* remove */
"action": "remove",
"big_map": $bignum }
|| { /* copy */
"action": "copy",
"source_big_map": $bignum,
"destination_big_map": $bignum }
|| { /* alloc */
"action": "alloc",
"big_map": $bignum,
"key_type": $micheline.007-PsDELPH1.michelson_v1.expression,
"value_type": $micheline.007-PsDELPH1.michelson_v1.expression } ... ]
If you are not interested in building an indexer, a more practical approach is using the Better Call Dev API. There is a route /bigmap/{network}/{ptr}/keys
which takes the network name and the big map id and returns the big map keys. It also has a few options that let you see the big map keys at a particular block height.
You can see an example in their UI: Dexter tzBTC/XTZ liquidity providers.
(pair (big_map %debits address tez) (big_map %credits address tez))
. Why do you want to know which big_maps they are, without knowing which is which? – Tom Dec 2 '19 at 13:29Big_map 1
), this means you need to consider the storage type, in order to distinguish the big_maps from other values which are encoded as integers. Unless you are willing to delegate this task to someone else (like tzstats), that's it, I think. – Tom Dec 4 '19 at 14:56tezos-client
. It would not be absurd to want such a feature in the client. – arvidj Dec 5 '19 at 9:46