Some API queries accept optional parameters Option that can be omitted.

How are those queries written with the javascript API?

For example:

api.query.preimage.preimageFor() takes an Option<(H256,u32)> and returns the preimage of given hash and legth.

However this option can be set to None (in the Dev console for example) then it returns a list of preimages, how is that query written in javascript?

pi = await api.query.preimage.preimageFor(None), what is None?

1 Answer 1


you can use .entries() to retrieve all the info, check the docs https://polkadot.js.org/docs/api/cookbook/storage/#how-do-i-use-entrieskeys-on-double-maps

In your case you can use something like could work

const allEntries = await api.query.preimage.preimageFor.entries();
allEntries.forEach(([{ args: [[hash,len]] }, value]) => {
  console.log(`hash: ${hash}, len: ${len}, value: ${value.toHuman()}`);


  • thanks! I would have not guessed this. I did not associate preimageFor with being a map-type storage entry... thanks!
    – rvalle
    Oct 25, 2023 at 13:09

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.