SuiNS SDK
Use the SuiNS SDK to interact with the Sui Name Service. Install the SDK, attach the suins() extension to a Sui client, and query SuiNS data such as name records under client.suins.
Install the SuiNS SDK with npm i @mysten/suins, then attach the suins() extension to a Sui client with $extend(). SuiNS methods are then available under client.suins.
How do I install the SuiNS SDK?
Install the SuiNS SDK alongside the Sui TypeScript SDK (@mysten/sui):
- npm
- Yarn
- pnpm
$ npm i @mysten/suins @mysten/sui
$ yarn add @mysten/suins @mysten/sui
$ pnpm add @mysten/suins @mysten/sui
What does the suins client extension do?
The suins() extension adds SuiNS functionality to any Sui client, exposed under client.suins.
You should keep only 1 extended client throughout your app, API, or script. For example, in React, you should use a context to provide the client.
How do I add SuiNS methods to a Sui client?
Always keep the dependency updated so you get the latest constants. The SDK's built-in constants include the SuiNS package IDs for Mainnet and Testnet, and these change on every package upgrade. If you do not, some of your transactions might fail to build.
Attach SuiNS to a Sui client by passing the suins() extension to the client's $extend() method, which adds the SuiNS methods under client.suins. Pass no arguments to use the built-in constants for Mainnet and Testnet, or pass a packageInfo object to target any other deployment.
- Network initializer
- Constants initializer
import { suins } from '@mysten/suins';
import { SuiGrpcClient } from '@mysten/sui/grpc';
// Re-use the Sui client of your project rather than creating a new one.
const client = new SuiGrpcClient({
network: 'testnet',
baseUrl: 'https://fullnode.testnet.sui.io:443',
}).$extend(suins());
// SuiNS methods are now available under client.suins.
const nameRecord = await client.suins.getNameRecord('example.sui');
import { suins, type PackageInfo } from '@mysten/suins';
import { SuiGrpcClient } from '@mysten/sui/grpc';
const packageInfo: PackageInfo = {
packageId: '0x...',
packageIdV1: '0x...',
// ... other required fields
};
const client = new SuiGrpcClient({
network: 'localnet',
baseUrl: 'http://localhost:9000',
}).$extend(suins({ packageInfo }));
This example targets a local network at http://localhost:9000 and is for local development only.
The PackageInfo type defines the required fields. For current Mainnet and Testnet values, see the SuiNS active constants, which SuiNS maintains. Do not copy package IDs from documentation, because they change on every package upgrade.