Integration

The JS library is available on NPM https://www.npmjs.com/package/@solana/spl-name-service

Resolve a Twitter handle

Direct look up

To resolve the public key associated to a Twitter handle

const pubkey = await getTwitterRegistry(connection, twitterHandle);

Reverse look up

To resolve the Twitter handle associated to the public key

const [twitterHandle] = await getHandleAndRegistryKey(
connection,
pubkey
);

Resolve a .sol domain name

To resolve the public key associated to a .sol domain name

// Address of the SOL TLD
export const SOL_TLD_AUTHORITY = new PublicKey(
"58PwtjSDuFHuUkYjH9BYnnQKHfwo9reZhC2zMJv9JPkx"
);
export const getInputKey = async (input: string) => {
let hashed_input_name = await getHashedName(input);
let inputDomainKey = await getNameAccountKey(
hashed_input_name,
undefined,
SOL_TLD_AUTHORITY
);
return { inputDomainKey: inputDomainKey, hashedInputName: hashed_input_name };
};
// ...
const { inputDomainKey } = await getInputKey(input);
const registry = await NameRegistryState.retrieve(
connection,
inputDomainKey
);