The RPC (currently delphinet), allows you to query a contract's storage and big map key at a particular block id.

GET ../<block_id>/context/big_maps/<big_map_id>/<script_expr>

GET ../<block_id>/context/contracts/<contract_id>/storage

My intuition is that if you query a contract at block X, the storage and big map values you get back for block X include the changes from the operations of block X. Is this correct?


Yes, the context queried in the RPC is the context resulting from the operations in that block. This can be demonstrated thus:

Consider the contract store_string.tz:

parameter string ;
storage (option string);
code { CAR;
       NIL operation;

It takes a string as a parameter and stores it. We originate the contract in a local sandbox:

$ tezos-client originate contract store_string transferring 0 from bootstrap1 \ 
                         running ~/store_string.tz  --init None --burn-cap 1

and bake in another terminal:

$ tezos-client bake for bootstrap2

Here is my receipt, abbreviated:

Operation found in block: BMAvJZqXQGmHhBybem2iRWfvZuK5d2i5ZbK4aj59DZ4gzcp6KwP (pass: 3, offset: 0)
This sequence of operations was run:
New contract KT1PcdVdbupFbMscwLmxEe1DEKPbwobCpnqk originated.
The operation has only been included 0 blocks ago.
We recommend to wait more.
Use command
  tezos-client wait for ooQ3bo5ncArZnR5fBSzeon5nSmf5brvW7DnHtH81xf5DKrEYn9J to be included --confirmations 30 --branch BL6LcKc7fm6PKV8V7Rn2hzWesZGfWQe9DJp47tUzPEnHZx273oh
and/or an external block explorer.
Contract memorized as store_string.

Thus the contract was originated in block BMAvJZqXQGmHhBybem2iRWfvZuK5d2i5ZbK4aj59DZ4gzcp6KwP with address KT1PcdVdbupFbMscwLmxEe1DEKPbwobCpnqk.

Let's inspect the storage of the contract in the block where it was originated:

$ tezos-client rpc get /chains/main/blocks/BMAvJZqXQGmHhBybem2iRWfvZuK5d2i5ZbK4aj59DZ4gzcp6KwP/context/contracts/KT1PcdVdbupFbMscwLmxEe1DEKPbwobCpnqk/storage
{ "prim": "None" }

The storage is None, as expected.

Now, let's update its storage with a transaction:

$ tezos-client transfer 0 from bootstrap1 to store_string --arg '"test!"' --burn-cap 1

and bake in another terminal:

$ tezos-client bake for bootstrap2

From the abbreviated receipt :

Operation found in block: BM3rZ6CzSxZ7XHqsHnbJAP3bUd8Ey5zzE3bxt3u2v9GRSdesUgU (pass: 3, offset: 0)

we see that the transaction was included in block BM3rZ6CzSxZ7XHqsHnbJAP3bUd8Ey5zzE3bxt3u2v9GRSdesUgU. Let's inspect the storage of our contract at that very block:

$ tezos-client rpc get /chains/main/blocks/BM3rZ6CzSxZ7XHqsHnbJAP3bUd8Ey5zzE3bxt3u2v9GRSdesUgU/context/contracts/KT1PcdVdbupFbMscwLmxEe1DEKPbwobCpnqk/storage
{ "prim": "Some", "args": [ { "string": "test!" } ] }

We see that the storage is updated.

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.