Skip to Content

TypeScript SDK

The Supra L1 TypeScript SDK provides a convenient way to interact with and perform operations on Supra. It offers a set of utility functions, classes, and types to simplify the integration process and enhance developer productivity.

Install the TypeScript SDK

npm install supra-ts-sdk

Requires Node.js 18 or later.

Import the Package

import { SupraAccount, SupraClient, Network, HexString } from 'supra-ts-sdk'

SupraAccount, HexString, BCS, TxnBuilderTypes, and TypeTagParser are re-exported by supra-ts-sdk, so everything comes from this single entry point.



Example

Initialize a new project

mkdir supra-quickstart && cd supra-quickstart npm init -y npm install --save-dev tsx mkdir src

tsx runs TypeScript files directly and needs no tsconfig.json. ts-node does not run with TypeScript 7, so these steps do not use it. They were run with Node.js 24.1.0, npm 11.3.0, supra-ts-sdk 1.2.0 and tsx 4.23.15, the latest versions on npm on 2026-10-19.

Install the TypeScript SDK

npm install supra-ts-sdk

Import dependencies

import { SupraAccount, SupraClient, Network, HexString } from 'supra-ts-sdk'

Initialize the SupraClient

The constructor is synchronous. Pass a predefined network and the chain ID and RPC URL are resolved for you — Network.TESTNET is chain ID 6, Network.MAINNET is chain ID 8. Create one client and reuse it.

const supra = new SupraClient({ network: Network.TESTNET })

To point at a custom node instead, pass rpcUrl and chainId directly:

const supra = new SupraClient({ rpcUrl: 'https://rpc-testnet.supra.com', chainId: 6, })

Initialize a SupraAccount

const senderAccount = new SupraAccount() console.log('Sender: ', senderAccount.address().toString())

This generates a new account on every run and does not store its private key. To keep an account, see Create Supra Accounts.

Fund the account with the Testnet faucet

The faucet call returns the hash of the funding transaction before the transaction executes. The account does not exist on chain until it does, and a transaction from it fails with Resource not found: 0x1::account::Account until then. waitForAccount calls getAccountInfo until the account exists. The full code below declares it before the async function.

const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) async function waitForAccount(supra: SupraClient, address: HexString) { for (let attempt = 0; attempt < 30; attempt++) { try { return await supra.account.getAccountInfo({ accountAddress: address }) } catch { await sleep(1000) } } throw new Error('The account did not appear on chain within 30 seconds') } console.log( 'Funding Sender With Faucet: ', await supra.faucet.fundAccountWithFaucet({ accountAddress: senderAccount.address(), }), ) await waitForAccount(supra, senderAccount.address())

The faucet limits what each account and IP address can request; see Faucet.

Set the receiver address

const receiverAddress = new HexString('0xb8922417130785087f9c7926e76542531b703693fdc74c9386b65cf4427f4e80')

Transfer supra to the receiver address

Important: When sending to a newly generated address, see Sending Tokens to New Accounts for recipient initialization behavior.

// To Transfer Supra Coin From Sender To Receiver const txResData = await supra.coin.transferSupraCoin({ senderAccount, receiverAccountAddress: receiverAddress, amount: BigInt(100000000), optionalTransactionArgs: { enableTransactionWaitAndSimulationArgs: { enableWaitForTransaction: true, enableTransactionSimulation: true, }, }, }) console.log('Transfer SupraCoin TxRes: ', txResData)

Full quickstart code

import { SupraAccount, SupraClient, Network, HexString } from "supra-ts-sdk"; const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); // An account is created on chain by the transaction that funds it, so reads and // transactions from it fail until then. async function waitForAccount(supra: SupraClient, address: HexString) { for (let attempt = 0; attempt < 30; attempt++) { try { return await supra.account.getAccountInfo({ accountAddress: address }); } catch { await sleep(1000); } } throw new Error("The account did not appear on chain within 30 seconds"); } (async () => { // The client is synchronous to construct. // Network.TESTNET resolves the chain ID and RPC URL for you. const supra = new SupraClient({ network: Network.TESTNET }); // Generate a new SupraAccount. const senderAccount = new SupraAccount(); console.log("Sender: ", senderAccount.address().toString()); // Fund the sender account with the Testnet faucet and wait until it exists. console.log( "Funding Sender With Faucet: ", await supra.faucet.fundAccountWithFaucet({ accountAddress: senderAccount.address(), }) ); await waitForAccount(supra, senderAccount.address()); // Set the receiver address const receiverAddress = new HexString( "0xb8922417130785087f9c7926e76542531b703693fdc74c9386b65cf4427f4e80" ); // To Transfer Supra Coin From Sender To Receiver const txResData = await supra.coin.transferSupraCoin({ senderAccount, receiverAccountAddress: receiverAddress, amount: BigInt(100000000), optionalTransactionArgs: { enableTransactionWaitAndSimulationArgs: { enableWaitForTransaction: true, enableTransactionSimulation: true, }, }, }); // Output the transaction data console.log("Transfer SupraCoin TxRes: ", txResData); })();

Execute the code: npx tsx src/quickstart.ts

Last updated on