SuiNS SDK
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.
Use the SuiNS SDK to interact with the Sui Name Service. Query SuiNS data in a usable way and build transactions that interact with service names.
To get started:
- Install the SDK.
- Attach the
suins()extension to your Sui client. - Call SuiNS methods under
client.suins.
How do I install the SuiNS SDK?
- Using @mysten/sui
- Using @mysten/sui.js
To use with the latest version of the TypeScript SDK, install using:
- npm
- Yarn
- pnpm
$ npm i @mysten/suins
$ yarn add @mysten/suins
$ pnpm add @mysten/suins
To use with the older version (prior to 1.x) of the TypeScript SDK (0.54.1), install using:
- npm
- Yarn
- pnpm
$ npm i @mysten/suins@0.0.3
$ yarn add @mysten/suins@0.0.3
$ pnpm add @mysten/suins@0.0.3
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.