11

Babylon will have a new RPC to query big map value according to this link http://tezos.gitlab.io/babylonnet/api/rpc.html#get-block-id-context-big-maps-big-map-id-script-expr

I tried using it with a new contract. I deployed this contract https://babylonnet.tzscan.io/KT1DT9YwHdSbZuVuZDjd1SMUcfXm57R5bE9v

If I understood correctly, the id of my big map should be 22

Knowing that my big map got initialized with a key tz1bwsEWCwSEXdRvnJxvegQZKeX5dj6oKEys

What is the correct way to get the value using either the cli or rpc?

I have tried:

tezos get element tz1bwsEWCwSEXdRvnJxvegQZKeX5dj6oKEys of big map 22

http://babylonnet-node.tzscan.io/chains/main/blocks/head/context/big_maps/22/tz1bwsEWCwSEXdRvnJxvegQZKeX5dj6oKEys

Both do not work. If I understand correctly, I will probably need to encode my key. I am unsure about what the required encoding is and can't seem to find an example that works.

2 Answers 2

8

The new CLI and RPC for big map expect hash of a script expression, instead of the raw expression. To obtain the hash you can e.g.:

tezos-client hash data '"tz1bwsEWCwSEXdRvnJxvegQZKeX5dj6oKEys"' of type address

This will print hashes in bunch of different formats - you want the one with the label Script-expression-ID-Hash, e.g. exprv6UsC1sN3Fk2XfgcJCL8NCerP5rCGy1PRESZAqr7L2JdzX55EN.

Then you can use this with the CLI:

tezos-client get element exprv6UsC1sN3Fk2XfgcJCL8NCerP5rCGy1PRESZAqr7L2JdzX55EN of big map 22

and RPC at:

/chains/main/blocks/head/context/big_maps/22/exprv6UsC1sN3Fk2XfgcJCL8NCerP5rCGy1PRESZAqr7L2JdzX55EN

Edit:

A new CLI command has been added for simpler big map access:

tezos-client get big map value for '"tz1bwsEWCwSEXdRvnJxvegQZKeX5dj6oKEys"' of type address in <src>

where <src> can be an alias, a key, or a literal (in your case KT1DT9YwHdSbZuVuZDjd1SMUcfXm57R5bE9v).

2
  • It might be worth mention why this has changed. 1) Using GET instead of POST for this query is semantically more sound, this query only requests data and does not change anything on the backend. 2) Before Carthagenet, a contract could only have one big map, now it can have multiple big maps. Each of those big maps have a unique identifying key.
    – MCH
    Commented Jun 18, 2020 at 16:35
  • Actually, the "new CLI command" get big map value is now marked as deprecated.
    – arvidj
    Commented Feb 18, 2021 at 13:22
6

The cli command is tezos-client get big map value for <key> of type <type of the key> in <contract>. By adding the -l option, we also get the RPC: /chains/main/blocks/head/context/contracts/<contract address>/big_map_get.

Actually, you do not need to know the big map index, if several big_maps with the same type of keys are stored, they will all be searched for the key.

2
  • 1
    get big map value is listed as deprecated now =(
    – Justin
    Commented Mar 2, 2020 at 22:22
  • 1
    I will say get big map value is much easier for the development process. I still see a lot of contracts designed such that they can continue using this command even though it is listed as deprecated. Of course, it only works for a big map that is in the left side of a pair at the top of a contracts storage.
    – MCH
    Commented Jun 18, 2020 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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