2

I'm trying to view the contents of a big_map in the storage of a smart contract. However, querying my Tezos node doesn't seem to provide that information. Is there a way of using the RPC interface to directly obtain the elements contained within a big_map?

2

As of 004_Pt24m4xi:

You can use the big_map_get RPC to get individual values out.

There is also a tezos-client command for this. (By passing -l we can see how it works through the RPC.)

$ tezos-client -l get big map value for 1 of type nat in KT1Qu32f8N5RLPoku5n8itiGaJ1a3eJDj5gu
...
>>>>2: http://localhost:18731/chains/main/blocks/head/context/contracts/KT1Qu32f8N5RLPoku5n8itiGaJ1a3eJDj5gu/big_map_get
  { "key": { "int": "1" }, "type": { "prim": "nat" } }
<<<<2: 200 OK
  { "int": "2" }
2

It is also possible to use the binary raw context RPC to explore the entire contents of the big_map, all at once or in pieces. I won't go into the details; they are difficult and seem out of scope. The relevant path is:

/chains/main/blocks/head/context/raw/bytes/contracts/index/...path/to/your/contract.../big_map

Be careful. If you experiment with context/raw/bytes outside of a sandbox, use ?depth=1 to avoid overloading your node by requesting the entire context at once.

The depth query parameter also enables you to scan the contents of a very large big_map, over multiple requests.


The protocol does not store the actual keys of the big_map in the context. It only stores the hashes of the keys. This means you cannot obtain the actual entries in the big_map (particularly, the keys) without either:

  1. Scanning (non-pruned!) blocks in the chain for operation receipts of transfers to your contract, which include the big_map_diff with the actual keys, or
  2. just knowing the keys somehow, and hashing them to find the corresponding entries.

As a hack, to waste some space in exchange for convenience, it is possible to store the unhashed key again inside the value. Then scanning the contents with context/raw/bytes can reveal the keys.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.