1

Is it possible to do a multiQuery querying multiple types and multiple blockhashes? Even same type and different block hashes would be helpful. Something along the lines of

const multiQueryResult = await api.queryMulti([
  [api.query.timestamp.now, BLOCK_HASH_1],
  [api.query.timestamp.now, BLOCK_HASH_2],
]);

1 Answer 1

1

From what I understand it is not possible, let me explain. The api needs to decorate the metadata per request (if not already cached) depending on the runtime required at that block. Back in older polkadot-js versions we had the .at() key for storage queries that would allow us to specify the block at which we wanted to query so it would look like api.query.timestamp.now.at(<BLOCK_HASH>). That has now been deprecated and replaced with const apiAt = api.at(<BLOCK_HASH>) where you then use the apiAt variable we just created to query your call like so apiAt.query.timestamp.now().

Here is an example of some code that will make it clearer.

/**
 * Using api.at(). The following blockhashes are on Kusama, and far enough
 * apart to demonstrate the use of different runtimes.
 */
// 0x62b04760a9ec2b2ab7beaecb6dbe48be59cc1f3ba3b327d159502c40b6f111fa Block 16449318
const apiAtBlockHash1 = await api.at('0x62b04760a9ec2b2ab7beaecb6dbe48be59cc1f3ba3b327d159502c40b6f111fa');
// 0x0b55de2436b21bb63db2406d32eaa2daaf731f672a2cfa1ab42dd997fd83d51f Block 15000000
const apiAtBlockHash2 = await api.at('0x0b55de2436b21bb63db2406d32eaa2daaf731f672a2cfa1ab42dd997fd83d51f');

const a1 = await apiAtBlockHash1.query.timestamp.now();
const a2 = await apiAtBlockHash2.query.timestamp.now();
console.log(a1.toString(), a2.toString());

Now if we were to use the example you referenced in your question, the api is going to use the latest block as its reference for the query. So given the following example, both timestamps will be exactly the same because the api decorated at the same block for each call. Passing in the blockhash wont help as an argument either because timestamp.now doesn't take in any arguments.

/**
 * Using the example you have above
 */
const multiQueryResult = await api.queryMulti([
            [api.query.timestamp.now, '0x62b04760a9ec2b2ab7beaecb6dbe48be59cc1f3ba3b327d159502c40b6f111fa'],
            [api.query.timestamp.now, '0x0b55de2436b21bb63db2406d32eaa2daaf731f672a2cfa1ab42dd997fd83d51f'],
]);

console.log(multiQueryResult[0].toString(), multiQueryResult[1].toString());

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.