Sui Typescript SDK Quick Start
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/sui.js
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/gas (default) |
Devnet | https://fullnode.devnet.sui.io:443 | https://faucet.devnet.sui.io/gas |
Testnet | https://fullnode.testnet.sui.io:443 | https://faucet.testnet.sui.io/gas |
Mainnet | https://fullnode.mainnet.sui.io:443 | null |
Migrate to version 0.38.0
The Sui TypeScript SDK was refactored beginning with version 0.38.0. If you are updating from an earlier version of the SDK, there are some changes you should consider when updating your code.
Module structure
The Sui TypeScript SDK is now divided into modular components. Before version 0.38.0, you imported the complete SDK module. Now, you upload the individual packages of the SDK module instead. See the Architecture section for the list of packages.
Deprecated classes
The Sui TypeScript SDK deprecates the following classes with version 0.38.0:
JsonRpcProvider
- TheJsonRpcProvider
class is deprecated in favor of thesuiClient
class when creating a client for a Sui network. See Network Interactions with SuiClient for more information.SignerWithProver
andRawSigner
- Key pairs now directly support signing transactions and messages without the need of aSigner
class. See the Key pairs topic for more information.signAndExecuteTransactionBlock
- This method was not deprecated, but is now part ofSuiClient
.Connection
classes - TheConnection
classes (Connection
,devnetConnection
, and so on) have been deprecated in favor of usingsuiClient
for establishing the connection. See Network Interactions with SuiClient for more information.- The
superstruct
type definitions forJsonRPCProvider
types are replaced with generated types exported from@mysten/sui.js/client
. The new type definitions are pure typescript types that you can't use for runtime validation. - A more stable JSON-RPC API has reduced the need for many of the SDK "getter" methods, which are now deprecated.
Signing transaction blocks
Signing and sending transaction blocks changes slightly with the deprecation of the Signer
pattern. For an example of transaction signing, see the
Sui Programmable Transaction Blocks Basics topic.
Faucet requests
The ability to request SUI from a faucet is not part of SuiClient
as it was with
JsonRpcProvider
. Instead, you must use the requestSuiFromFaucetV0
method from
@mysten/sui.js/faucet
. The @mysten/sui.js/faucet
import also provides a getFaucetHost
method
to retrieve the faucet URL for localnet
, testnet
, or devnet
networks.
import { getFaucetHost, requestSuiFromFaucetV0 } from '@mysten/sui.js/faucet';
await requestSuiFromFaucetV0({
host: getFaucetHost('devnet'),
recipient: '<SUI_ADDRESS>',
});
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.js/client
- A client for interacting with Sui RPC nodes.@mysten/sui.js/bcs
- A BCS builder with pre-defined types for Sui.@mysten/sui.js/transaction
- Utilities for building and interacting with transactions.@mysten/sui.js/keypairs/*
- Modular exports for specific KeyPair implementations.@mysten/sui.js/verify
- Methods for verifying transactions and messages.@mysten/sui.js/cryptography
- Shared types and classes for cryptography.@mysten/sui.js/multisig
- Utilities for working with multisig signatures.@mysten/sui.js/utils
- Utilities for formatting and parsing various Sui types.@mysten/sui.js/faucet
- Methods for requesting SUI from a faucet.