Suryansh Singh
Suryansh Singh

Reputation: 67

How to find all the polkadot accounts with index or identity attached

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.

Upvotes: 4

Views: 554

Answers (1)

Shawn Tabrizi
Shawn Tabrizi

Reputation: 12434

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) […] ]

Upvotes: 5

Related Questions