Documentation v1.0 has been released! Staking Guide, Protocols, Glossary, FAQ, and Support sections have been added.

Sui

Learn how to integrate Sui staking using Everstake Wallet SDK.

Getting Started

You can use two different options to implement Sui operations with the Everstake wallet SDK.

Option 1: REST API

You can use REST API to call methods which are described in Swagger with detailed examples

https://wallet-sdk-api.everstake.one

To use transactions from REST API you can use the following approach:

import { Transaction } from '@mysten/sui/transactions';
import { SuiClient } from '@mysten/sui/client';

const client = new SuiClient({url: suiRpcUrl});

// REST API json response object
const apiResponse = {...}

const apiResponseString = JSON.stringify(apiResponse)

const tx = Transaction.from(apiResponseString)

// Sign and execute the transaction
const txDetails = await client.signAndExecuteTransaction({
  transaction: tx,
  signer: yourKeypair
});

// transaction hash
console.log(tx.digest); 

Option 2: TypeScript library

You can install and import Wallet SDK for Javascript/TypeScript.

Step. 1: Installing the Library

Install the npm library or yarn by copying the code below.

Step. 2: Import Wallet SDK

After installing the package, you can import the Sui module and use the SDK:

Import ES6

Import ES5

Getting Info

The Sui SDK provides several read-only methods to retrieve information about balances and stakes:

  • getBalanceByAddress(address): Retrieves the Sui balance for a given address. Returns a BigNumber representing the balance in MIST.

  • getStakes(address): Gets all staking positions for a given address.

Balance Example

Staking Positions Example

Stake

stake(amount): Creates a transaction to stake SUI tokens with a validator. This method requires the amount to be greater than or equal to the minimum required for staking (1^9 MIST).

Stake Code Example

Unstake

unstake(stakedSuiId): Creates a transaction to unstake previously staked SUI tokens. This method requires the ID of the staked SUI object to be withdrawn.

Unstake Code Example

Balance

getBalanceByAddress(address): Retrieves the Sui balance for a given address. This method returns a BigInt representing the balance in the smallest denomination (MIST). To convert to SUI, divide by 10^9.

Balance Code Example

Get Existing Stakes

The getStakeBalanceByAddress method retrieves all delegated stakes for a specific address.

  • getStakeBalanceByAddress(address): returns all staking information for the given address

Get Stake Balance Code Example

Send transfer

sendTransfer(recipientAddress, amount): Creates a transaction to transfer SUI tokens to a recipient. This method requires the recipient's address and the amount to send.

Send Transfer Code Example