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];
}