4

I want to find all the polkadot accounts which either have an index or have registered their identity; similar to https://polkascan.io/polkadot/account/identities and https://polkascan.io/polkadot/indices/account.

1 Answers1

5

Using JS, you can simply iterate over the storage items which track this information for all accounts.

For example, to get all accounts with some Identity information, you would do:

let users = await api.query.identity.identityOf.entries()

This will return all the different storage keys and values under the identityOf storage item. Those keys will have the AccountId as the last 32 bytes of the key.

> util_crypto.encodeAddress(users[0][0].slice(-32))

"5CMbC573hpNWhJVTe4Qo7AtFQntAQDWKKVX9kt9WAHGy413y"
> users[0][1].toJSON()


{…}
​
deposit: 1666666666660
​
info: Object { additional: [], display: {…}, legal: {…}, … }
​
judgements: Array [ (2) […] ]
Shawn Tabrizi
  • 12,206
  • 1
  • 38
  • 69