问题描述
我想找到所有有索引或已注册身份的 polkadot 账户;类似于 https://polkascan.io/polkadot/account/identities 和 https://polkascan.io/polkadot/indices/account。
解决方法
使用 JS,您可以简单地迭代跟踪所有帐户的此信息的存储项。
例如,要获取具有某些身份信息的所有帐户,您可以执行以下操作:
let users = await api.query.identity.identityOf.entries()
这将返回 identityOf
存储项下的所有不同存储键和值。这些键将 AccountId
作为键的最后 32 个字节。
> util_crypto.encodeAddress(users[0][0].slice(-32))
"5CMbC573hpNWhJVTe4Qo7AtFQntAQDWKKVX9kt9WAHGy413y"
> users[0][1].toJSON()
{…}
deposit: 1666666666660
info: Object { additional: [],display: {…},legal: {…},… }
judgements: Array [ (2) […] ]