2

For a Polkadot parachain (Zeitgeist) query, I need to add the block hash to get historical data. See this example:

Block timestamp query

When I try to try to run the same query in polkadot.js, I get an error when I try and add a blockHash as a parameter

// This causes an error - how to provide block hash to this function?

const blockHash = "0x52352ca066543d41aacb0c6419e5bb7e2d9ee621b3d8dabe2c2174ce2c5f86c5"
const unixTimestamp = await api.query.timestamp.now(blockHash);

could you help me figure out how I should provide this parameter?

the error:

ba@https://polkadot.js.org/apps/modu.ac52cd44a2179bd7.js:1:79374
overrideNoSub@https://polkadot.js.org/apps/modu.ac52cd44a2179bd7.js:1:91709
10589/u/</<@https://polkadot.js.org/apps/modu.ac52cd44a2179bd7.js:1:105234
10589/u/</<@https://polkadot.js.org/apps/modu.ac52cd44a2179bd7.js:1:105195
10589/u/<@https://polkadot.js.org/apps/modu.ac52cd44a2179bd7.js:1:105338
anonymous/<@https://polkadot.js.org/apps/page.e64d864372c5d12b.js line 1464 > Function:4:49
anonymous@https://polkadot.js.org/apps/page.e64d864372c5d12b.js line 1464 > Function:7:67
30145/T</Z</<@https://polkadot.js.org/apps/page.e64d864372c5d12b.js:1464:1810

2 Answers 2

5

For querying anything historical in polkadot-js there is the .at property to the ApiPromise.

Example:

const block = '0x52352ca066543d41aacb0c6419e5bb7e2d9ee621b3d8dabe2c2174ce2c5f86c5'
const apiAt = await api.at(block);
const timestamp = await apiAt.query.timestamp.now();
console.log(timestamp);

I wrote a more in detail response on the .at for another user a while ago here: PolkadotJs Api: queryMulti with different blockHashes

Hope that helps :)

1

Found the following info (will try):

https://polkadot.js.org/docs/api/examples/promise/read-storage-at/

Your Answer

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

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