Quick Start - Integration

Quickly integrate SNS domains into your dApps to build a more personalized, and secure user experience. The methods below can be used to integrate the most popular SNS functionalities. 1.) Resolve domains - As outlined in our resolve section, resolution allows a user entered .sol domain to resolve to its corresponding wallet address. Use this for functionality like transfers, tracking, sharing, etc.

import { resolve } from "@bonfida/spl-name-service";

const domain = "sns.sol" // With or without .sol

// The config argument to resolve is optional
// If allowPDA is true, a list of program IDs is required
const resolveConfig = { allowPda: true, programIds: ["..."] }

const resolvedAddress = await resolve(connection, domain, resolveConfig)

2.) Primary domains - In identity elements of your dApp, we always recommend that you use primary domains as outlined in our primary domains section. Primary domains are specifically set by users are their preferred on chain identity.

import { getPrimaryDomain } from "@bonfida/spl-name-service";

const { domain, reverse } = await getPrimaryDomain(connection, domainOwnerPublicKey);

3.) Domain records - Domain records can be used as a powerful tool in social graphing and bridging a traditional social presence to Web3 identities. Records are feature rich, and the methods below are a quick integration guide, a full breakdown can be found in the records section.

import { Record, getMultipleRecordsV2, verifyStaleness } from "@bonfida/spl-name-service";

const domain = "sns.sol"

const recordsToFetch = [Record.Discord, Record.Twitter, Record.Telegram];

const recordOptions = { deserialize: true };

const domainRecords = getMultipleRecordsV2(
  connection,
  domain,
  recordsToFetch,
  recordOptions,
 );

// This example arbitrarily selects the first record of the list
// In practice you should filter based on your needs
const isFreshRecord = await verifyStaleness(connection, domainRecords[0], domain);

Last updated