Post
Share your knowledge.

Building Your First dApp with the Sui TypeScript SDK — Step-by-Step
Who this is for: Frontend and full-stack developers who want to integrate Sui into web apps, wallets, or dashboards without relying solely on the CLI.
Goal: By the end of this article, you’ll be able to:
Install and configure the Sui TypeScript SDK.
Connect to testnet and query blockchain data.
Execute transactions programmatically.
Handle gas, effects, and common SDK pitfalls.
Part 1 — What the Sui TypeScript SDK Does
The Sui TypeScript SDK is your bridge between a browser/server app and the Sui network. It:
Connects to RPC nodes to read data (objects, events, balances).
Submits transactions (transfers, Move calls).
Works in Node.js and browser environments.
Powers many wallets and dApps in the Sui ecosystem.
Part 2 — Prerequisites
Before you start, you’ll need:
Node.js ≥ 18
npm or yarn
A Sui wallet (e.g., Sui Wallet extension) for private key management.
Some testnet SUI (get from faucet via CLI or wallet).
Part 3 — Installing the SDK
- Create a new project:
mkdir sui-ts-demo && cd sui-ts-demo npm init -y
- Install the SDK:
npm install @mysten/sui.js
- (Optional) Install dotenv for managing environment variables:
npm install dotenv
Part 4 — Connecting to the Network
index.js (or index.ts if using TypeScript):
import 'dotenv/config'; import { JsonRpcProvider, Connection } from '@mysten/sui.js';
// Create a connection to the Sui testnet const provider = new JsonRpcProvider( new Connection({ fullnode: 'https://fullnode.testnet.sui.io/' }) );
// Test connection: Get latest block info async function getLatestBlock() { const latest = await provider.getLatestCheckpointSequenceNumber(); console.log('Latest Checkpoint:', latest); }
getLatestBlock();
Run:
node index.js
If successful, you’ll see a checkpoint number — meaning your SDK can talk to the network.
Part 5 — Querying Data
Example: Fetch your SUI balance.
const address = process.env.MY_ADDRESS; // set in .env const coins = await provider.getCoins({ owner: address, coinType: '0x2::sui::SUI' });
console.log('Your coins:', coins.data); console.log('Total balance:', coins.data.reduce((sum, c) => sum + BigInt(c.balance), 0n).toString());
Part 6 — Sending a Transaction (Transfer SUI)
1) Import Keypair
If you’re storing your key locally (dev/test only — never expose production keys):
import { Ed25519Keypair, RawSigner } from '@mysten/sui.js';
const secretKey = process.env.SECRET_KEY_BASE64; // base64-encoded private key const keypair = Ed25519Keypair.fromSecretKey(Buffer.from(secretKey, 'base64')); const signer = new RawSigner(keypair, provider);
2) Build and Send
async function sendSui(recipient, amount) { const tx = await signer.paySui({ inputCoins: (await provider.getCoins({ owner: keypair.getPublicKey().toSuiAddress() })).data.map(c => c.coinObjectId), recipients: [recipient], amounts: [amount], // in MIST (1 SUI = 1_000_000_000 MIST) });
console.log('Transfer digest:', tx.digest); }
sendSui('0xRECIPIENT_ADDRESS', 1_000_000);
Part 7 — Calling a Move Function If you’ve published a package (e.g., counter from Article 1):
async function incrementCounter(packageId, objectId, by) { const tx = await signer.executeMoveCall({ packageObjectId: packageId, module: 'counter', function: 'inc', typeArguments: [], arguments: [objectId, by], gasBudget: 20_000_000, });
console.log('Increment digest:', tx.digest); }
Part 8 — Common Problems & Solutions
| Problem | Cause | Fix |
|---|---|---|
| Invalid base64 string | Wrong key encoding | Ensure key is raw private key in base64 |
| Insufficient gas | No testnet SUI or small coin selected | Use faucet & merge coins via CLI before SDK call |
| Transaction never confirms | Wrong RPC endpoint | Use official testnet/mainnet fullnode URLs |
| Type errors in TS | SDK version mismatch | Install latest @mysten/sui.js and match TS config |
Part 9 — Development Tips
-
Never hardcode keys in source — use .env.
-
Batch reads — provider supports queries for multiple objects in one call.
-
Use events — subscribe to specific events from your Move modules.
-
Test in localnet — Sui CLI can run a local network for integration testing.
✅ You can now:
Connect to Sui from JavaScript/TypeScript.
Query balances and objects.
Send SUI and call Move functions programmatically.
- Sui
- SDKs and Developer Tools
Sui is a Layer 1 protocol blockchain designed as the first internet-scale programmable blockchain platform.
- How to Maximize Profit Holding SUI: Sui Staking vs Liquid Staking616
- Why does BCS require exact field order for deserialization when Move structs have named fields?65
- Multiple Source Verification Errors" in Sui Move Module Publications - Automated Error Resolution55
- Sui Move Error - Unable to process transaction No valid gas coins found for the transaction419
- Sui Transaction Failing: Objects Reserved for Another Transaction410