@mysten/sui v2.0 and a new dApp Kit are here! Check out the migration guide
Mysten Labs SDKs

Quick Start

Get started with the Sui TypeScript SDK in a few minutes. This guide walks you through creating a keypair, funding it from a faucet, and checking your balance.

Install

Create a new project and install the SDK:

mkdir hello-sui
cd hello-sui
npm init -y
npm i @mysten/sui

The SDK is published as an ESM only package. Make sure your package.json includes "type": "module":

{
	"type": "module"
}

If you are using TypeScript, your tsconfig.json should use a compatible moduleResolution setting such as "NodeNext", "Node16", or "Bundler".

Step 1: Create a keypair and get SUI

Create a setup.js file that generates a new keypair, requests SUI from the faucet, and prints your secret key for later use:

import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
import { getFaucetHost, requestSuiFromFaucetV2 } from '@mysten/sui/faucet';

// Generate a new keypair
const keypair = new Ed25519Keypair();

console.log('Address:', keypair.toSuiAddress());
console.log('Secret key:', keypair.getSecretKey());

// Request SUI from the devnet faucet
await requestSuiFromFaucetV2({
	host: getFaucetHost('devnet'),
	recipient: keypair.toSuiAddress(),
});

console.log('Faucet request sent! Save the secret key above for the next step.');

Run it:

node setup.js

Save the secret key that gets printed — you'll use it in the next step.

Step 2: Check your balance

Create a balance.js file that imports your keypair from the secret key and checks the balance:

import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
import { SuiGrpcClient } from '@mysten/sui/grpc';
import { MIST_PER_SUI } from '@mysten/sui/utils';

// Import the keypair using the secret key from step 1
const keypair = Ed25519Keypair.fromSecretKey('suiprivkey1...'); // paste your secret key here

const grpcClient = new SuiGrpcClient({ network: 'devnet' });

const { balance } = await grpcClient.getBalance({
	owner: keypair.toSuiAddress(),
});

const sui = Number(balance.balance) / Number(MIST_PER_SUI);
console.log(`Address: ${keypair.toSuiAddress()}`);
console.log(`Balance: ${sui} SUI`);

Run it:

node balance.js

Faucet

Devnet, Testnet, and local networks include faucets that mint SUI. Use requestSuiFromFaucetV2 to request SUI programmatically:

import { getFaucetHost, requestSuiFromFaucetV2 } from '@mysten/sui/faucet';

await requestSuiFromFaucetV2({
	host: getFaucetHost('testnet'),
	recipient: '0xYourAddress',
});

Faucets on Devnet and Testnet are rate limited. If you hit the limit, wait before trying again. For testnet, you can also get SUI through the web UI at faucet.sui.io or via the Sui Discord faucet channels.

Next steps

On this page