1

For queries such as api.query.identity.indentityOf(AccountID32) it is possible within Polkadot.JS.org/apps to include or not include a parameter:

Option not included

Option included

I would like to do the same via typescript but I'm unable to determine the right syntax. I have tried:

  • api.query.identity.identityOf()
  • api.query.identity.identityOf(null)
  • api.query.identity.identityOf(undefined)

1 Answer 1

1

Querying all entries of a map can be done with the .entries() function:

import { ApiPromise, WsProvider } from '@polkadot/api';

const wsProvider = new WsProvider('wss://rpc.polkadot.io');
const api = await ApiPromise.create({ provider: wsProvider });

const identities = await api.query.identity.identityOf.entries();

identities.forEach(([key, identity]) => {
      console.log(key.toHuman(), identity.toHuman());
});

In this case, however, you probably want to use the entriesPaged function since it are so many entries and the probably cannot be loaded at once:

... // Setup same as above

const PAGE_SIZE = 50;
let last_key = null;
let identities = [];

for (;;) {
    const new_identities = await api.query.identity.identityOf.entriesPaged({ args: [], pageSize: PAGE_SIZE, startKey: last_key });
    console.log(`Loading ${new_identities.length} more identities…`);
    identities = identities.concat(new_identities);
    if (new_identities.length < PAGE_SIZE) {
        console.log(`Done! Loaded ${identities.length} identities.`);
        break;
    }
    last_key = new_identities[new_identities.length - 1][0];
}
1

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.