Join our
Discord!
LogoLogo
SupraScan ExplorerStarKey WalletDiscord
MoveVM
  • Network
  • Oracles
  • Automation
  • SupraNova
  • Guides
MoveVM
  • Overview
  • Getting Started
    • Install Supra CLI with Docker
    • Create a Supra Account
    • Create a Move Package
      • Initialize a Package
      • Write a Module
      • Compile and Publish
      • Interact with a Package
    • Create a dApp with StarKey
  • Network Information
  • Token Standards
  • Learn Move 101
    • Getting Started with Move
    • Unsigned Integers in Move
    • Math Operations in Move
    • Using Vectors in Move
    • Reading Resource Data with borrow_global
    • Passing Data in Move: Value vs. Reference
    • Adding Elements with vector::push_back
    • Emitting Events with event::emit
  • Move Book
    • Getting Started
      • Modules and Scripts
      • Move Tutorial
    • Primitive Types
      • Integers
      • Bool
      • Address
      • Vector
      • Signer
      • References
      • Tuples and Unit
    • Basic Concepts
      • Local Variables and Scope
      • Equality
      • Abort and Assert
      • Conditionals
      • While, For, and Loop
      • Functions
      • Structs and Resources
      • Constants
      • Generics
      • Type Abilities
      • Uses and Aliases
      • Friends
      • Packages
      • Package Upgrades
      • Unit Tests
    • Global Storage
      • Structure
      • Operators
    • Reference
      • Standard Library
      • Coding Conventions
  • TypeScript SDK
    • Guides
      • Create Supra Accounts
      • Publish a Package
    • Documentation
    • Repository
  • Rest API
    • Mainnet
      • Accounts
      • Faucet
      • Transactions
      • Block
      • View
      • Consensus
      • Events
      • Tables
    • Testnet
      • Accounts
      • Faucet
      • Transactions
      • Block
      • View
      • Events
      • Tables
  • Developer Resources
    • Supra Dapp Templates
    • Supra Move VS Code Extension
  • Links
    • Supra DevHub
    • SupraScan Block Explorer
    • StarKey Wallet
    • Live Data Feeds
    • Whitepapers
    • Security Audits
    • Supra's Official GitHub
Powered by GitBook
On this page
  • Install the TypeScript SDK
  • Import the Package
  • Example
Edit on GitHub

TypeScript SDK

PreviousCoding ConventionsNextGuides

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-l1-sdk

Import the Package

import { HexString, SupraAccount, SupraClient, BCS } from "supra-l1-sdk";


Example

1

Initialize a new project

npm init && npm add -D typescript @types/node ts-node && npx tsc --init && mkdir src && > src/quickstart.ts
2

Install the TypeScript SDK

npm install supra-l1-sdk
3

Import dependencies

import {
  HexString,
  SupraAccount,
  SupraClient,
  BCS,
  TxnBuilderTypes,
} from "supra-l1-sdk";
4

Initialize the SupraClient

let supraClient = await SupraClient.init(
  "https://rpc-testnet.supra.com/"
);
5

Initialize a SupraAccount

let senderAccount = new SupraAccount(
  Uint8Array.from(
    Buffer.from(
      "2b9654793a999d1d487dabbd1b8f194156e15281fa1952af121cc97b27578d89",
      "hex"
    )
  )
);
6

Fund the account with the testnet faucet

console.log(
  "Funding Sender With Faucet: ",
  // To Fund Account With Test Supra Tokens
  await supraClient.fundAccountWithFaucet(senderAccount.address())
);
7

Set the receiver address

let receiverAddress = new HexString(
  "0xb8922417130785087f9c7926e76542531b703693fdc74c9386b65cf4427f4e80"
);
8

Transfer supra to the receiver address

// To Transfer Supra Coin From Sender To Receiver
let txResData = await supraClient.transferSupraCoin(
  senderAccount,
  receiverAddress,
  BigInt(100000000),
  {
    enableTransactionWaitAndSimulationArgs: {
      enableWaitForTransaction: true,
      enableTransactionSimulation: true,
    },
  }
);
console.log("Transfer SupraCoin TxRes: ", txResData);
9

Full quickstart code

quickstart.ts
import {
    HexString,
    SupraAccount,
    SupraClient
  } from "supra-l1-sdk";
  
  (async () => {
  
    // To Create Instance Of Supra Client, But In This Method We Don't Need To Pass ChainId.
    // ChainId Will Be Identified At Instance Creation Time By Making RPC Call.
    let supraClient = await SupraClient.init(
      "https://rpc-autonet.supra.com/"
    );
  
    //Init a SupraAccount from a private key.
    let senderAccount = new SupraAccount(
      Uint8Array.from(
        Buffer.from(
          "2b9654793a999d1d487dabbd1b8f194156e15281fa1952af121cc97b27578d89",
          "hex"
        )
      )
    );

    //Fund the sender account with the testnet faucet
    await supraClient.fundAccountWithFaucet(senderAccount.address())

    //Set the receiver address
    let receiverAddress = new HexString(
      "0xb8922417130785087f9c7926e76542531b703693fdc74c9386b65cf4427f4e80"
    );

    // To Transfer Supra Coin From Sender To Receiver
    let txResData = await supraClient.transferSupraCoin(
      senderAccount,
      receiverAddress,
      BigInt(1000),
      {
        enableTransactionWaitAndSimulationArgs: {
          enableWaitForTransaction: true,
          enableTransactionSimulation: true,
        },
      }
    );

    //Output the transaction data
    console.log("Transfer SupraCoin TxRes: ", txResData);

  })();
10

Execute the code: npx ts-node src/quickstart.ts

Guides

SDK Documentation

SDK Repository