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)import { resolveDomain } from "@solana-name-service/sns-sdk-kit";
const domain = "sns.sol" // With or without .sol
// The options argument is not required to be passed
// If allowPDA is true, a list of program IDs is required.
const resolveOptions = { allowPda: true, programIds: ["..."] }
const resolvedAddress = await resolveDomain({ rpc, domain, options:resolveOptions });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);import { getPrimaryDomain } from "@solana-name-service/sns-sdk-kit";
import { Address } from "@solana/kit";
const userWallet = "36Dn3RWhB8x4c83W6ebQ2C2eH9sh5bQX2nMdkP2cWaA4" as Address
const {
domainAddress, // Address of domain account, not the user wallet address
domainName: primaryDomain,
stale: isPrimaryDomainStale
} = await getPrimaryDomain({ rpc, walletAddress:userWallet });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);import {
Record,
getDomainRecords,
} from "@solana-name-service/sns-sdk-kit";
const domain = "sns.sol"
const recordsToFetch = [Record.Discord, Record.Twitter, Record.Telegram];
// Optionally chose to deserialize the returned content
// Optionally pass verifiers to use custom oracle during right of association verification
const recordOptions = { deserialize: true, verifiers: undefined };
const domainRecords = getRecords({
rpc,
domain,
records: recordsToFetch,
options: recordOptions,
});
// This example arbitrarily selects the first record of the list
// In practice you should filter based on your needs
const recordToCheck = domainRecords[0];
const recordContent = recordToCheck.deserializedContent;
const isRecordVerified = recordToCheck.verification.roa;
const isRecordStale = recordToCheck.verification.staleness;Last updated