Skip to main content

Resolve a web3name

A web3name can be resolved in a similar manner to how a DID is resolved. Resolving the web3name will provide the same information as resolving a DID does.

To query and retrieve the DID document associated with a web3name, you can use the following code example:

import * as Kilt from '@kiltprotocol/sdk-js'

export async function queryDidDocument(
web3Name: Kilt.Did.Web3Name
): Promise<Kilt.DidDocument> {
const api = Kilt.ConfigService.get('api')

console.log(`Querying the blockchain for the web3name "${web3Name}"`)
// Query the owner of the provided web3name.
const encodedWeb3NameOwner = await api.call.did.queryByWeb3Name(web3Name)

// Extract the DidDocument and other linked information from the encodedWeb3NameOwner.
const { document } = Kilt.Did.linkedInfoFromChain(encodedWeb3NameOwner)

return document
}

In the code example above, the queryDidDocument function takes a web3Name parameter, which represents the web3name to be resolved. It internally uses the api.call.did.queryByWeb3Name method to query the information of the provided web3name from the blockchain.

The function then decodes the result using Kilt.Did.linkedInfoFromChain to extract the associated DID document and any other linked blockchain accounts. Finally, it returns the resolved DID document.