> For the complete documentation index, see [llms.txt](/llms.txt)

# Sui TypeScript SDK

TypeScript SDK for building on the Sui blockchain



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 [#installation]

<CodeBlockTabs defaultValue="npm">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="npm">
      npm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="pnpm">
      pnpm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="yarn">
      yarn
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="bun">
      bun
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="npm">
    ```bash
    npm i @mysten/sui
    ```
  </CodeBlockTab>

  <CodeBlockTab value="pnpm">
    ```bash
    pnpm add @mysten/sui
    ```
  </CodeBlockTab>

  <CodeBlockTab value="yarn">
    ```bash
    yarn add @mysten/sui
    ```
  </CodeBlockTab>

  <CodeBlockTab value="bun">
    ```bash
    bun add @mysten/sui
    ```
  </CodeBlockTab>
</CodeBlockTabs>

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

```json
{
	"type": "module"
}
```

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

## Module packages [#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`](/sui/clients): A client for interacting with Sui RPC nodes.
* [`@mysten/sui/bcs`](/sui/bcs): A BCS builder with pre-defined types for Sui.
* [`@mysten/sui/transactions`](/sui/transactions/basics): Utilities for building and interacting
  with transactions.
* [`@mysten/sui/keypairs/*`](/sui/cryptography/keypairs): Modular exports for specific KeyPair
  implementations.
* [`@mysten/sui/verify`](/sui/cryptography#verifying-signatures): Methods for verifying transactions
  and messages.
* [`@mysten/sui/cryptography`](/sui/cryptography): Shared types and classes for cryptography.
* [`@mysten/sui/multisig`](/sui/cryptography/signers/multisig): Utilities for working with multisig
  signatures.
* [`@mysten/sui/utils`](/sui/utils): Utilities for formatting and parsing various Sui types.
* [`@mysten/sui/faucet`](#faucet): Methods for requesting SUI from a faucet.
* [`@mysten/sui/zklogin`](/sui/zklogin): Utilities for working with zkLogin.

## Network locations [#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/v3/gas`    |
| Testnet | `https://fullnode.testnet.sui.io:443` | `https://faucet.testnet.sui.io/v3/gas`   |
| Mainnet | `https://fullnode.mainnet.sui.io:443` | `null`                                   |

<Callout type="warn">
  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](https://sui.io/developers#dev-tools) using the **Node Service** tab.
</Callout>

## Quick start [#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 [#create-a-project]

```sh
mkdir hello-sui
cd hello-sui
npm init -y
npm pkg set type=module
npm i @mysten/sui
```

### Step 1: Create a keypair and get SUI [#step-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:

```typescript
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
import { getFaucetHost, requestSuiFromFaucetV3 } 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 requestSuiFromFaucetV3({
	host: getFaucetHost('devnet'),
	recipient: keypair.toSuiAddress(),
});

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

Run it:

```sh
node setup.ts
```

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

<Callout type="warn">
  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.
</Callout>

### Step 2: Check your balance [#step-2-check-your-balance]

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

```typescript
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.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:

```sh
node balance.ts
```

### Step 3: Transfer SUI [#step-3-transfer-sui]

Create a `transfer.ts` file that sends SUI to another address and logs the transaction effects:

```typescript
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:

```sh
node transfer.ts
```

### Faucet [#faucet]

Use `requestSuiFromFaucetV3` on Devnet and Testnet. It fetches a challenge from `/v3/challenge`,
computes Argon2d proof-of-work, and submits the proof to `/v3/gas`:

```typescript
import { getFaucetHost, requestSuiFromFaucetV3 } from '@mysten/sui/faucet';

const result = await requestSuiFromFaucetV3({
	host: getFaucetHost('testnet'),
	recipient: '0xYourAddress', // Replace with your Sui address.
	timeout: 180_000,
});

console.log(result.digest, result.amountMist);
```

V3 credits the recipient's address balance, not a coin object. Its response contains `digest`,
`recipient`, `amountMist`, and `difficulty`; it does not contain V2's `coins_sent`. Amounts are
returned as decimal strings to preserve precision. The faucet sets the payout amount.

Set `host` to the faucet's origin (scheme, hostname, and optional port), such as
`https://faucet.testnet.sui.io`. The API must serve `/v3/challenge` and `/v3/gas` at the origin
root. Path prefixes such as `/faucet` are not supported; any path in `host` is discarded.

Optional `headers` apply to both requests. The `timeout` covers fetching, solving, and submission,
and defaults to 180,000 milliseconds. Pass an `AbortSignal` as `signal` to cancel earlier.

The helper uses Node's asynchronous native Argon2d when available (Node 24.7 or newer), with Noble
as the fallback for Node 22 and browsers. Native hashing does not require an addon. Browser apps can
run the helper in a Web Worker to keep proof-of-work off the UI thread.

For a local **no-PoW faucet**, keep using V2:

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

await requestSuiFromFaucetV2({
	host: getFaucetHost('localnet'),
	recipient: '0xYourAddress', // Replace with your Sui address.
});
```

For a local **PoW faucet**, use `requestSuiFromFaucetV3` and set `host` to its origin, with
`/v3/challenge` and `/v3/gas` served at the origin root. If it listens on the default local faucet
port, use `getFaucetHost('localnet')`. The helper does not infer the protocol from the host or fall
back to V2.

V3 refreshes expired challenges before submission but never automatically retries a payout. HTTP 429
throws `FaucetRateLimitError`. Other HTTP errors throw `FaucetError`, which exposes `status` and,
when provided by the server, `code` and a transaction `digest`. Non-JSON error responses use a
fallback message and preserve the parse error as `cause`. If a digest is present, resolve that
transaction before requesting another payout. A timeout or connection loss during submission does
not prove the payout failed; do not blindly retry it.

<Callout type="info">
  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 through the [Sui
  Discord](https://discord.gg/sui) faucet channels.
</Callout>

## Next steps [#next-steps]

* [Building Transactions](/sui/transactions/basics): create and compose transactions
* [Signing and Execution](/sui/transactions/signing-and-execution): sign and submit transactions
* [Coins and Balances](/sui/transactions/coins-and-balances): work with tokens
* [Client Setup](/sui/clients): configure clients for different networks
