Query

Query DID name

Example code was used to query user's DID name by tokenId andyou can note the specific block by overrides parameter.

import {NewHashKeyDID} from "hashkeydid";
// tokenId: 1222
// overrides(optional): {"blockTag": 16513266} (search at block number 16513266)
async function QueryDidByTokenId(){
    const did = await NewHashKeyDID("https://openapi2.platon.network/rpc");
    const did_name = await did.TokenId2Did(1222, {blockTag: 16513266});
    console.log(did_name)
}

Query DID tokenId

Code was used to query user's tokenId by DID name and you can note the specific block by overrides parameter.

import {NewHashKeyDID} from "hashkeydid";
// did name: terro.key
// overrides(optional): {"blockTag": 16513266} (search at block number 16513266)
async function QueryTokenIdByDid(){
    const did = await NewHashKeyDID("https://openapi2.platon.network/rpc");
    const tokenId = await did.Did2TokenId("terro.key", {blockTag: 16513266})
    console.log(tokenId);
}

Query DID name by address

Code was used to query DID name by DID address when you set resolver is true. you can note the specific block by overrides/opts parameter.

import {NewHashKeyDIDResolver} from "hashkeydid";
// DID address: 0xteDBB6048b0B9107a21d81E345afe0789229DbTs
// overrides(optional): {"blockTag": 16513266} (search at block number 16513266)
async function QueryDIDNameByAddr(){
    const resolver = await NewHashKeyDIDResolver("https://openapi2.platon.network/rpc");
    const did_name = await resolver.GetDIDNameByAddr("0xteDBB6048b0B9107a21d81E345afe0789229DbTs", {blockTag: 16513266});
    console.log(did_name);
}

Query DID name by address force

Querying DID name by DID address force even if the resolver is false. you can note the specific block by overrides/opts parameter.

import {NewHashKeyDIDResolver} from "hashkeydid";
// DID address: 0xteDBB6048b0B9107a21d81E345afe0789229DbTs
// overrides(optional): {"blockTag": 16513266} (search at block number 16513266)
async function QueryDIDNameByAddrForce(){
    const resolver = await NewHashKeyDIDResolver("https://openapi2.platon.network/rpc");
    const did_name = await resolver.GetDIDNameByAddrForce("0xteDBB6048b0B9107a21d81E345afe0789229DbTs", {blockTag: 16513266});
    console.log(did_name);
}

Query DID address by DID name

Querying DID address by DID name. you can note the specific block by overrides/opts parameter.

import {NewHashKeyDID} from "hashkeydid";
// DID name: herro.key
// overrides(optional): {"blockTag": 16513266} (search at block number 16513266)
async function QueryAddrByDIDName(){
    const did = await NewHashKeyDID("https://openapi2.platon.network/rpc");
    const addr = await did.GetAddrByDIDName("herro.key", {blockTag: 16513266});
    console.log(addr)
}

Query DID KYC information

Querying user's KYC information by tokenId, KYCProvider, KYCId and note the specific block by overrides/opts parameters.

import {NewHashKeyDID} from "hashkeydid";
// tokenId: 1222
// KYCProvider: 0xdeDBB6048b0B9107a21d81E345afe0789229Dbac
// KYCId: 1
// overrides: {"blockTag": 16513266} (search at block number 16513266)
async function QueryKYCInfo(){
    const did = await NewHashKeyDID("https://openapi2.platon.network/rpc");
    const kyc = await did.GetKYCInfo(1222, "0xdeDBB6048b0B9107a21d81E345afe0789229Dbac", 1, {blockTag: 16513266});
    console.log(kyc);
}

Query DID metadata avatar image url

Querying DID user's metadata avatar url and you can note the specific block by overrides/opts parameter.

import {NewHashKeyDIDResolver} from "hashkeydid";
// did: terro.key
// overrides(optional): {"blockTag": 16513266} (search at block number 16513266)
async function QueryMetadataImageByDIDName(){
    const resolver = await NewHashKeyDIDResolver("https://openapi2.platon.network/rpc");
    const metadata = await resolver.GetMetadataImageByDIDName("terro.key", {blockTag: 16513266});
    console.log(metadata)
}

Query DID resolver avatar url.

We'v already provided four blockchains info about chainList pramater, you can also customize the chain information according to the following format

{
    "1":      {"network": "Ethereum", "RPC": "https://eth-mainnet.nodereal.io/v1/1659dfb40aa24bbb8153a677b98064d7"},
    "137":    {"network": "Polygon", "RPC": "https://matic-mainnet-archive-rpc.bwarelabs.com"},
    "1284":   {"network": "Moonbeam", "RPC": "https://moonbeam.public.blastapi.io"},
    "8217":   {"network": "Klaytn", "RPC": "https://klaytn01.fandom.finance"},
    "210425": {"network": "PlatON", "RPC": "https://openapi2.platon.network/rpc"},
}
import {NewHashKeyDIDResolver} from "hashkeydid";
// did: terro.key
// chainList(optional): {"1": {"network": "Ethereum", "RPC": "https://eth-mainnet.nodereal.io/v1/1659dfb40aa24bbb8153a677b98064d7"}}
// overrides(optional): {"blockTag": 16513266} (search at block number 16513266)
async function QueryResolverAvatarByDIDName(){
    const resolver = await NewHashKeyDIDResolver("https://openapi2.platon.network/rpc");
    const avatar = await resolver.GetAvatarByDIDName("terro.key", {blockTag: 16513266}, "https://eth-mainnet.nodereal.io/v1/1659dfb40aa24bbb8153a677b98064d7");
    console.log(avatar);
}

Query DID address based on different blockchain

User can bond the address for different chains to DID account, and use the following method to query address information with coinType parameter.

import {NewHashKeyDIDResolver} from "hashkeydid";
// tokenId: 1222
// coinType: 1 eg: 1->ethereum, 137->polygon
async function QueryBlockChainAddress(){
    const resolver = await NewHashKeyDIDResolver("https://openapi2.platon.network/rpc");
    const addr = await resolver.GetBlockChainAddress(1222, 1);
    console.log(addr);
}

Last updated