0

The RPC for querying big maps mentions script_expr, but no where else in the Tezos Developer Documentation is it mentioned.

  • What is script_expr?
  • Where can developers learn more about it?
  • What libraries support it?
1

script_expr in this RPC means any Michelson expression. It is used to specify the key of the big_map that the RPC queries.

2
  • What is the expected format of script_expr? I don't imagine it is going to read PUSH nat 3; PUSH address "tz1..."; PAIR? And where can developers learn more about it?
    – MCH
    Jan 17 '21 at 17:13
  • 1
    Assuming from your comment that your big map is indexed by keys of type pair address nat, you can build the expression as follows: $ tezos-client convert data 'Pair "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" 3' from Michelson to JSON. Jan 18 '21 at 15:14
1

What is script_expr?

Prior to the Babylon protocol, a contract could only have one big map. This big map had to be located in a storage structured like this: or (big_map ...) .... There is a deprecated route to query a big map in the location.

Since Babylon, a contract can have multiple big maps. Each of these big maps have a unique id (an integer). Using this route, you can query the key of a particular big map. However, you must prepare the key data in a particular format of Michelson called script_expr. It is the Blake2B hash of packed data that is then encoded into Base58.

Here is an example copied from this answer.

We want the script_expr for an address KT1PWx2mnDueood7fEmfbBDKx1D9BAnnXitn.

  1. Pack the key (this is available in the RPC, the tezos-client and various libraries). 050a0000001601a3d0f58d8964bd1b37fb0a0c197b38cf46608d4900

  2. Hash it with Blake2B hash and digest size of 32. d8a60c00b3c8f62cc2b3b8006b1858a621b5b74e06d3c82916659beaa24c8f67

  3. Prepend "0d2c401b". 0d2c401bd8a60c00b3c8f62cc2b3b8006b1858a621b5b74e06d3c82916659beaa24c8f67

  4. Base58 encode the result with checksum. exprvAHu1SyoiSzyh9w7GPfifvyrNiMb442y7Q2MA8tcPCGPajxRH6

From the command line you can do:

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

Script-expression-ID-Hash: exprvAHu1SyoiSzyh9w7GPfifvyrNiMb442y7Q2MA8tcPCGPajxRH6

Where can developers learn more about it?

This first part should cover most of what a developer needs to know about script_expr if they need to implement in a library. However, if you need more information it is best to start looking at the source code.

You need to understand how pack works. Blake2B in the tezos source code comes from digestf which is an OCaml wrapper around the High Assurance Cryptographic Library. Then you can see where script_expr is defined.

What libraries support it?

These libraries all support packing and have Blake2B and Base58 tools as dependencies. You can follow the example in the first section.

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.