Sui TypeScript SDK
The Sui TypeScript SDK is a modular library of tools for interacting with the Sui blockchain. Use it to send queries to RPC nodes, build and sign transactions, and interact with a Sui or local network.
Installation
npm i @mysten/suiThe 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".
Module packages
The SDK contains a set of modular packages that you can use independently or together. Import just what you need to keep your code light and compact.
@mysten/sui/client- A client for interacting with Sui RPC nodes.@mysten/sui/bcs- A BCS builder with pre-defined types for Sui.@mysten/sui/transactions- Utilities for building and interacting with transactions.@mysten/sui/keypairs/*- Modular exports for specific KeyPair implementations.@mysten/sui/verify- Methods for verifying transactions and messages.@mysten/sui/cryptography- Shared types and classes for cryptography.@mysten/sui/multisig- Utilities for working with multisig signatures.@mysten/sui/utils- Utilities for formatting and parsing various Sui types.@mysten/sui/faucet- Methods for requesting SUI from a faucet.@mysten/sui/zklogin- Utilities for working with zkLogin.
Network locations
The following table lists the locations for Sui networks.
| Network | Full node | faucet |
|---|---|---|
| local | http://127.0.0.1:9000 (default) | http://127.0.0.1:9123/v2/gas (default) |
| Devnet | https://fullnode.devnet.sui.io:443 | https://faucet.devnet.sui.io/v2/gas |
| Testnet | https://fullnode.testnet.sui.io:443 | https://faucet.testnet.sui.io/v2/gas |
| Mainnet | https://fullnode.mainnet.sui.io:443 | null |
Use dedicated nodes/shared services rather than public endpoints for production apps. The public
endpoints maintained by Mysten Labs (fullnode.<NETWORK>.sui.io:443) are rate-limited, and support
only 100 requests per 30 seconds or so. Do not use public endpoints in production applications with
high traffic volume.
You can either run your own Full nodes, or outsource this to a professional infrastructure provider (preferred for apps that have high traffic). You can find a list of reliable RPC endpoint providers for Sui on the Sui Dev Portal using the Node Service tab.
Quick start
Get started in a few minutes. This guide walks you through creating a keypair, funding it from a faucet, and checking your balance.
Create a project
mkdir hello-sui
cd hello-sui
npm init -y
npm pkg set type=module
npm i @mysten/suiStep 1: Create a keypair and get SUI
Create a setup.ts 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.tsSave the secret key that gets printed — you'll use it in the next step.
Logging secret keys to the console is only appropriate for quick demos like this. In real applications, never log or expose secret keys. Store them securely using environment variables, encrypted keystores, or a secrets manager.
Step 2: Check your balance
Create a balance.ts 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',
baseUrl: 'https://fullnode.devnet.sui.io:443',
});
const { balance } = await grpcClient.core.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.tsStep 3: Transfer SUI
Create a transfer.ts file that sends SUI to another address and logs the transaction effects:
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
import { SuiGrpcClient } from '@mysten/sui/grpc';
import { coinWithBalance, Transaction } from '@mysten/sui/transactions';
import { MIST_PER_SUI } from '@mysten/sui/utils';
const keypair = Ed25519Keypair.fromSecretKey('suiprivkey1...'); // paste your secret key here
const grpcClient = new SuiGrpcClient({
network: 'devnet',
baseUrl: 'https://fullnode.devnet.sui.io:443',
});
const tx = new Transaction();
tx.transferObjects(
[coinWithBalance({ balance: BigInt(0.1 * Number(MIST_PER_SUI)) })],
'0xRecipientAddress', // replace with the recipient's address
);
const result = await keypair.signAndExecuteTransaction({
transaction: tx,
client: grpcClient,
include: { effects: true, balanceChanges: true },
});
if (result.$kind === 'FailedTransaction') {
console.error('Transaction failed:', result.FailedTransaction.status.error?.message);
} else {
console.log('Transaction digest:', result.Transaction.digest);
console.log('Effects:', JSON.stringify(result.Transaction.effects, null, 2));
console.log('Balance changes:', JSON.stringify(result.Transaction.balanceChanges, null, 2));
}Run it:
node transfer.tsFaucet
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
- Building Transactions — create and compose transactions
- Signing and Execution — sign and submit transactions
- Coins and Balances — work with tokens
- Client Setup — configure clients for different networks