1

Using polkadot.js api:

  • How do I get from an address to the parent address/identity?
  • Is there any way to traverse from an identity to the sub-identities?

Just calling the identity of the address returns null

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

(async () => {

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

  var validator = { stash: "HyLisujX7Cr6D7xzb6qadFdedLt8hmArB6ZVGJ6xsCUHqmx" }; // METASPAN
  var identity = await api.query.identity.identityOf(validator.stash)
  console.log(identity.toString())
  // {"judgements":[[0,{"reasonable":null}]],"deposit":33333333000,"info":{"additional":[],"display":{"raw":"0x4d4554415350414e"},"legal":{"none":null},"web":{"none":null},"riot":{"none":null},"email":{"raw":"0x646572656b406d6574617370616e2e636f6d"},"pgpFingerprint":null,"image":{"none":null},"twitter":{"raw":"0x406d6574617370616e5f696f"}}}

  validator = { name: '☀️SHAWN☀️/08🚀', stash: 'GvBUeTDynB9A7fFDPoBt3RGXSjZVeCetoXjYQ44cMNp5myY' }
  identity = await api.query.identity.identityOf(validator.stash)
  console.log(identity.toString())
  // empty

  console.debug('done')

  setTimeout(() => {
    process.exit(0)
  }, 5000)

})()

1 Answer 1

2

If the identity is null, try querying superOf:

  const parent = await api.query.identity.superOf(validator.stash)
  //console.log(parent.toString())
  var [parentStash, subId] = parent.toJSON()
  console.log(parentStash, '-raw-', hexToString(subId.raw))

  var parentIdentity = await api.query.identity.identityOf(parentStash)
  var idj = parentIdentity.toJSON()
  console.log('parent name:', hexToString(idj.info.display.raw))

produces:

{"judgements":[[0,{"reasonable":null}]],"deposit":33333333000,"info":{"additional":[],"display":{"raw":"0x4d4554415350414e"},"legal":{"none":null},"web":{"none":null},"riot":{"none":null},"email":{"raw":"0x646572656b406d6574617370616e2e636f6d"},"pgpFingerprint":null,"image":{"none":null},"twitter":{"raw":"0x406d6574617370616e5f696f"}}}

JHDDYty2cU6vjWyMF2kvNK9hRMAgH9THwqvQpUzqQQs7KJr -raw- 08🚀
parent name: ☀️Shawn☀️
done

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.