Skip to main content

JavaScript SDK installation

Install JavaScript SDK v4 in an application that uses @solana/web3.js 1.x.

Install the packages

Install the SDK and its web3.js peer dependency:

npm install @bonfida/spl-name-service@^4 @solana/web3.js@^1.98.2

Import the SDK

The package root and category subpaths are supported. Use either style consistently with the application:

Package root
import {
getPrimaryDomain,
resolve,
safeResolve,
} from "@bonfida/spl-name-service";
Category subpaths
import { getPrimaryDomain } from "@bonfida/spl-name-service/address";
import { resolve, safeResolve } from "@bonfida/spl-name-service/domain";

CommonJS applications can load the same exports with require:

const { resolve, safeResolve } = require("@bonfida/spl-name-service");

Use safeResolve when .sol resolution must require matching SRS and SNS targets after SRS-backed resolution is enabled.

RPC Configuration

Create the web3.js Connection passed to RPC-backed SDK APIs with your Solana RPC endpoint:

import { Connection } from "@solana/web3.js";

const connection = new Connection("https://your-rpc-endpoint.example");

Next

Continue to the JavaScript SDK Quickstart to resolve a domain and query domain data.