Legacy Rust SDK
The Sui Rust SDK provides Rust wrappers for interacting with Sui networks. Two Rust SDK crates are available:
| Crate | Repository | Status | Use when |
|---|---|---|---|
sui-rust-sdk | MystenLabs/sui-rust-sdk | Current | Building new Rust integrations. Uses GraphQL RPC and gRPC. |
sui-sdk | MystenLabs/sui | Legacy | Maintaining existing integrations that depend on this crate. |
For new projects, use sui-rust-sdk. It is the actively maintained Rust SDK with support for the current Sui API surface.
Legacy sui-sdk crate
The legacy SDK crate lives in the crates/sui-sdk directory of the main Sui repository. It no longer includes a JSON-RPC client; it provides the wallet and client configuration layer used by the Sui CLI, which talks to Sui over gRPC.
Installation
Add the crate to your Cargo.toml:
[dependencies]
sui-sdk = { git = "https://github.com/MystenLabs/sui.git", package = "sui-sdk" }
SDK reference
The legacy SDK README describes what the crate provides and how to use the wallet from Rust:
This crate provides the wallet and client configuration layer that the Sui CLI and the tooling in this repository use to talk to a Sui network. Auto-generated documentation for this crate is here.
The JSON-RPC client this crate used to provide was removed together with the fullnode JSON-RPC service. For a general-purpose Rust SDK, use the sui-rust-sdk crate, which talks to Sui over gRPC and GraphQL.
What the crate provides
wallet_context::WalletContext: a keystore-backed wallet that signs transactions and executes them against the active network environment over gRPC.sui_client_config::SuiClientConfig: the persisted client configuration (client.yaml), including the named network environments and the active address.verify_personal_message_signature: verification of personal message signatures through a fullnode.
Getting started
Add the sui-sdk dependency as follows:
sui-sdk = { git = "https://github.com/mystenlabs/sui", package = "sui-sdk" }
tokio = { version = "1.2", features = ["full"] }
anyhow = "1.0"
The following example loads the wallet configuration written by the Sui CLI and reads the active address’s gas coins through the gRPC client of the active environment:
use sui_sdk::sui_client_config::SuiClientConfig;
use sui_sdk::wallet_context::WalletContext;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let config_path = sui_config::sui_config_dir()?.join(sui_config::SUI_CLIENT_CONFIG);
let mut wallet = WalletContext::new(&config_path)?;
let address = wallet.active_address()?;
let gas_objects = wallet.gas_objects(address).await?;
println!("Address {address} owns {} gas objects", gas_objects.len());
let client = wallet.grpc_client()?;
println!("Reference gas price: {}", client.get_reference_gas_price().await?);
Ok(())
}
Documentation for sui-sdk crate
GitHub Pages hosts the generated documentation for all Rust crates in the Sui repository.
Building documentation locally
You can also build the documentation locally. To do so,
-
Clone the
suirepo locally. Open a Terminal or Console and go to thesui/crates/sui-sdkdirectory. -
Run
cargo docto build the documentation into thesui/targetdirectory. Take note of location of the generated file from the last line of the output, for exampleGenerated /Users/foo/sui/target/doc/sui_sdk/index.html. -
Use a web browser, like Chrome, to open the
.../target/doc/sui_sdk/index.htmlfile at the location your console reported in the previous step.