Direct Lookup
Lookup domain information directly based on the human readable domain name.
In order to get the information of a domain name you need to:
Get the domain name public key
Retrieve the account info
import { getDomainKeySync, NameRegistryState } from "@bonfida/spl-name-service";
const domainName = "bonfida"; // With or without the .sol at the end
// Step 1
const { pubkey } = getDomainKeySync(domainName);
// Step 2
// The registry object contains all the info about the domain name
// The NFT owner is of type PublicKey | undefined
const { registry, nftOwner } = await NameRegistryState.retrieve(
connection,
pubkey
);
// Subdomain derivation
const subDomain = "dex.bonfida"; // With or without the .sol at the end
const { pubkey: subKey } = getDomainKeySync(subDomain);
// Record derivation (e.g IPFS record)
const record = "IPFS.bonfida"; // With or without the .sol at the end
const { pubkey: recordKey } = getDomainKeySync(record, true);
The retrieve method returns an object made of two fields:
registryis of typeNameRegistryStatenftOwneris of typePublicKey | undefinedWhen
nftOwneris of typePublicKeyit means that the domain is tokenized and the current NFT holder isnftOwner. When a domain is tokenizedregistry.owneris an escrow account that is program owner. Funds should be sent tonftOwnerWhen
nftOwneris of typeundefinedit means that the domain is not tokenized and funds should be sent toregistry.owner
NameRegistryState.retrieveBatch can be used to retrieve multiple name registries at once. Pass the connection, and an array of domain name public keys as arguments to the function.
Last updated