0.47.0 • Published 5 months ago

@mysten/sui.js v0.47.0

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
5 months ago

Sui TypeScript SDK

This is the Sui TypeScript SDK built on the Sui JSON RPC API. It provides utility classes and functions for applications to sign transactions and interact with the Sui network.

WARNING: Note that we are still iterating on the RPC and SDK API before TestNet, therefore please expect frequent breaking changes in the short-term. We expect the API to stabilize after the upcoming TestNet launch.

Working with DevNet

The SDK will be published to npm registry with the same bi-weekly release cycle as the DevNet validators and RPC Server. To use the SDK in your project, you can do:

$ npm install @mysten/sui.js

You can also use your preferred npm client, such as yarn or pnpm.

Working with local network

Note that the latest tag for the published SDK might go out of sync with the RPC server on the main branch until the next release. If you're developing against a local network, we recommend using the experimental-tagged packages, which contain the latest changes from main.

npm install @mysten/sui.js@experimental

Refer to the JSON RPC topic for instructions about how to start a local network and local RPC server.

Building Locally

To get started you need to install pnpm, then run the following command:

# Install all dependencies
$ pnpm install
# Run the build for the TypeScript SDK and all of its dependencies.
$ pnpm --filter @mysten/sui.js... build

Type Doc

You can view the generated Type Doc for the current release of the SDK at http://typescript-sdk-docs.s3-website-us-east-1.amazonaws.com/.

For the latest docs for the main branch, run pnpm doc and open the doc/index.html in your browser.

Usage

The JsonRpcProvider class provides a connection to the JSON-RPC Server and should be used for all read-only operations. The default URLs to connect with the RPC server are:

Examples:

Fetch objects owned by the address 0xbff6ccc8707aa517b4f1b95750a2a8c666012df3

import { JsonRpcProvider } from '@mysten/sui.js';
const provider = new JsonRpcProvider('https://gateway.devnet.sui.io:443');
const objects = await provider.getOwnedObjectRefs(
  '0xbff6ccc8707aa517b4f1b95750a2a8c666012df3'
);

Fetch transaction details from a transaction digest:

import { JsonRpcProvider } from '@mysten/sui.js';
const provider = new JsonRpcProvider('https://gateway.devnet.sui.io:443');
const txn = await provider.getTransaction(
  '6mn5W1CczLwitHCO9OIUbqirNrQ0cuKdyxaNe16SAME='
);

For any operations that involves signing or submitting transactions, you should use the Signer API. For example:

To transfer a 0x2::coin::Coin<SUI>:

import { Ed25519Keypair, JsonRpcProvider, RawSigner } from '@mysten/sui.js';
// Generate a new Keypair
const keypair = new Ed25519Keypair();
const signer = new RawSigner(
  keypair,
  new JsonRpcProvider('https://gateway.devnet.sui.io:443')
);
const transferTxn = await signer.transferObject({
  objectId: '0x5015b016ab570df14c87649eda918e09e5cc61e0',
  gasBudget: 1000,
  recipient: '0xd84058cb73bdeabe123b56632713dcd65e1a6c92',
});
console.log('transferTxn', transferTxn);

To split a 0x2::coin::Coin<SUI> into multiple coins

import { Ed25519Keypair, JsonRpcProvider, RawSigner } from '@mysten/sui.js';
// Generate a new Keypair
const keypair = new Ed25519Keypair();
const signer = new RawSigner(
  keypair,
  new JsonRpcProvider('https://gateway.devnet.sui.io:443')
);
const splitTxn = await signer..splitCoin({
  coinObjectId: '0x5015b016ab570df14c87649eda918e09e5cc61e0',
  // Say if the original coin has a balance of 100,
  // This function will create three new coins of amount 10, 20, 30,
  // respectively, the original coin will retain the remaining balance(40).
  splitAmounts: [10, 20, 30],
  gasBudget: 1000,
});
console.log('SplitCoin txn', splitTxn);

To merge two coins:

import { Ed25519Keypair, JsonRpcProvider, RawSigner } from '@mysten/sui.js';
// Generate a new Keypair
const keypair = new Ed25519Keypair();
const signer = new RawSigner(
  keypair,
  new JsonRpcProvider('https://gateway.devnet.sui.io:443')
);
const mergeTxn = await signer.mergeCoin({
  primaryCoin: '0x5015b016ab570df14c87649eda918e09e5cc61e0',
  coinToMerge: '0xcc460051569bfb888dedaf5182e76f473ee351af',
  gasBudget: 1000,
});
console.log('MergeCoin txn', mergeTxn);

To make a move call:

import { Ed25519Keypair, JsonRpcProvider, RawSigner } from '@mysten/sui.js';
// Generate a new Keypair
const keypair = new Ed25519Keypair();
const signer = new RawSigner(
  keypair,
  new JsonRpcProvider('https://gateway.devnet.sui.io:443')
);
const moveCallTxn = await signer.executeMoveCall({
  packageObjectId: '0x2',
  module: 'devnet_nft',
  function: 'mint',
  typeArguments: [],
  arguments: [
    'Example NFT',
    'An NFT created by the wallet Command Line Tool',
    'ipfs://bafkreibngqhl3gaa7daob4i2vccziay2jjlp435cf66vhono7nrvww53ty',
  ],
  gasBudget: 10000,
});
console.log('moveCallTxn', moveCallTxn);

To publish a package:

import { Ed25519Keypair, JsonRpcProvider, RawSigner } from '@mysten/sui.js';
import * as fs from 'fs/promises';
// Generate a new Keypair
const keypair = new Ed25519Keypair();
const signer = new RawSigner(
  keypair,
  new JsonRpcProvider('https://gateway.devnet.sui.io:443')
);
const bytecode = await fs.readFile('path/to/project/build/project_name/bytecode_modules/module_name.mv', 'base64');
const publishTxn = await signer.publish(
  {
    compiledModules: [bytecode.toString()],
    gasBudget: 1000
  }
);
console.log('publishTxn', publishTxn);
@infinitebrahmanuniverse/nolb-_mysmartian-sdkoyee-pepsuiet-wallet-adapter@everything-registry/sub-chunk-630sui-execution-handler@nhtera/flowx-ts-sdk-testnethaedaljs-sdk-v3-testkriya-dex-sdkkriya-perps-sdkkriya-sdkkriya-vault-sdkgoosebumps-sdkgize-dao-sdklibrary-suimarket-demomarket-sui-sdkendec-jsflowx-faas-sdkflowx-ts-sdkfake-user-walletexpand-networkethos-connectethos-connect-stagingethos-react2ethos-react2-tsethos-wallet-betaget-nftsgenerate-random-stringsgenerate-user-walletorao-sui-vrfomnisuiswap-sdkofficiaenimperiphery-sdk-for-testmycel-widgetnodejs-oraclenimbus-sui-connectornimbus-sui-kitnavi-sdknavi-sdk-testnatusnobismygit-infompay-sdk-suimsafe-sui3-sdkmultichain-walletkit-sdk-suiperps-db-clientsmove-mountainsmovex-swap-v2-sdkmesonfi-sdksavourlabs-wallet-sdkseapad-sdkreact-sui-walletstest-maven-sdktest-maven-xtest-maven2sdktest-dotnames-jstest-cetus-sui-clmm-sdktest-cetus-sui-sdktwa-sui-walletsow-sdksuidappadaptersuidoublesuihub-sdksuihub-swap-sdksui-multisig-jssui-scallop-sdk-testsui-cartonsui-dapp-kit-vuesui-sveltesui-walletsui-stakesuioopsimple-greet-metria-sdk-core-chainstria-sdk-core-chains-jatintransactions-helpersurfwaxtemp-opti-stake-sdk@kunalabs-io/sui-metamask-snap@kunalabs-io/sui-snap-wallet@mak201010/bluefin-v2-client@mak201010/library-sui@mak201010/wormhole-connect@mak201010/wormhole-connect-sdk@lit-protocol/pkp-sui@nightlylabs/nightly-connect-sui@polymedia/commando@polymedia/profile-sdk@polymedia/suits@msafe/sui-wallet@msafe/maven-x-sdk@msafe/sui-app-store@nightlylabs/wallet-selector-sui@nixjs23n6/asset-adapter@nixjs23n6/transaction-adapter@nixjs23n6/utilities-adapter@nixjs23n6/move-asset@nixjs23n6/move-transaction@fewcha/web3
0.44.0

7 months ago

0.42.0

8 months ago

0.37.1

10 months ago

0.37.0

10 months ago

0.46.0

6 months ago

0.46.1

6 months ago

0.39.0

9 months ago

0.43.0

7 months ago

0.45.1

6 months ago

0.45.0

6 months ago

0.41.1

8 months ago

0.41.2

8 months ago

0.41.0

9 months ago

0.43.3

7 months ago

0.43.1

7 months ago

0.43.2

7 months ago

0.47.0

5 months ago

0.38.0

9 months ago

0.40.0

9 months ago

0.33.0

1 year ago

0.36.0

11 months ago

0.34.1

12 months ago

0.34.0

12 months ago

0.35.1

11 months ago

0.35.0

11 months ago

0.32.2

1 year ago

0.32.1

1 year ago

0.32.0

1 year ago

0.30.0

1 year ago

0.31.0

1 year ago

0.26.1

1 year ago

0.26.0

1 year ago

0.29.0

1 year ago

0.29.1

1 year ago

0.27.0

1 year ago

0.28.0

1 year ago

0.20.0

1 year ago

0.21.0

1 year ago

0.22.0

1 year ago

0.25.0

1 year ago

0.19.0

1 year ago

0.23.0

1 year ago

0.24.0

1 year ago

0.17.0

1 year ago

0.17.1

1 year ago

0.18.0

1 year ago

0.16.0

1 year ago

0.15.0

1 year ago

0.13.0

2 years ago

0.14.0

2 years ago

0.11.0

2 years ago

0.12.0

2 years ago

0.10.0

2 years ago

0.9.0

2 years ago

0.8.0

2 years ago

0.6.2

2 years ago

0.4.0

2 years ago

0.7.0

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.0

2 years ago