Crate sui_sdk

source ·
Expand description

The Sui Rust SDK

It aims at providing a similar SDK functionality like the one existing for TypeScript. Sui Rust SDK builds on top of the JSON RPC API and therefore many of the return types are the ones specified in [sui_types].

The API is split in several parts corresponding to different functionalities as following:

  • CoinReadApi - provides read-only functions to work with the coins
  • EventApi - provides event related functions functions to
  • GovernanceApi - provides functionality related to staking
  • QuorumDriverApi - provides functionality to execute a transaction block and submit it to the fullnode(s)
  • ReadApi - provides functions for retrieving data about different objects and transactions
  • TransactionBuilder - provides functions for building transactions

§Usage

The main way to interact with the API is through the SuiClientBuilder, which returns a SuiClient object from which the user can access the various APIs.

§Getting Started

Add the Rust SDK to the project by running cargo add sui-sdk in the root folder of your Rust project.

The main building block for the Sui Rust SDK is the SuiClientBuilder, which provides a simple and straightforward way of connecting to a Sui network and having access to the different available APIs.

A simple example that connects to a running Sui local network, the Sui devnet, and the Sui testnet is shown below. To successfully run this program, make sure to spin up a local network with a local validator, a fullnode, and a faucet server (see here for more information).

use sui_sdk::SuiClientBuilder;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {

    let sui = SuiClientBuilder::default()
        .build("http://127.0.0.1:9000") // provide the Sui network URL
        .await?;
    println!("Sui local network version: {:?}", sui.api_version());

    // local Sui network, same result as above except using the dedicated function
    let sui_local = SuiClientBuilder::default().build_localnet().await?;
    println!("Sui local network version: {:?}", sui_local.api_version());

    // Sui devnet running at `https://fullnode.devnet.io:443`
    let sui_devnet = SuiClientBuilder::default().build_devnet().await?;
    println!("Sui devnet version: {:?}", sui_devnet.api_version());

    // Sui testnet running at `https://testnet.devnet.io:443`
    let sui_testnet = SuiClientBuilder::default().build_testnet().await?;
    println!("Sui testnet version: {:?}", sui_testnet.api_version());
    Ok(())

}

§Examples

For detailed examples, please check the APIs docs and the examples folder in the main repository.

Re-exports§

  • pub use sui_json as json;
  • pub use sui_json_rpc_types as rpc_types;
  • pub use sui_types as types;

Modules§

Structs§

  • SuiClient is the basic type that provides all the necessary abstractions for interacting with the Sui network.
  • A Sui client builder for connecting to the Sui network

Constants§