Interact with Sui over Rust SDK


The Sui SDK is a collection of Rust language JSON-RPC wrapper and crypto utilities you can use to interact with the Sui Devnet and Sui Full node.

The SuiClient can be used to create an HTTP or a WebSocket client (SuiClient::new). See our JSON-RPC doc for the list of available methods.

Note: As of Sui version 0.6.0, the WebSocket client is for subscription only; use the HTTP client for other API methods.


Find the rustdoc output for key Sui projects at:


Add the sui-sdk crate in your Cargo.toml file like so:

sui-sdk = { git = "" }

If you are connecting to the devnet, use the devnet branch instead:

sui-sdk = { git = "", branch = "devnet" }


Example 1 - Get all objects owned by an address

This will print a list of object summaries owned by the address "0xec11cad080d0496a53bafcea629fcbcfff2a9866":

use std::str::FromStr;
use sui_sdk::types::base_types::SuiAddress;
use sui_sdk::SuiClient;

async fn main() -> Result<(), anyhow::Error> {
    let sui = SuiClient::new("", None, None).await?;
    let address = SuiAddress::from_str("0xec11cad080d0496a53bafcea629fcbcfff2a9866")?;
    let objects = sui.read_api().get_objects_owned_by_address(address).await?;
    println!("{:?}", objects);

You can verify the result with the Sui Explorer if you are using the Sui Devnet Full node.

Example 2 - Create and execute transaction

Use this example to conduct a transaction in Sui using the Sui Devnet Full node:

use std::str::FromStr;
use sui_sdk::{
    crypto::{FileBasedKeystore, Keystore},
        base_types::{ObjectID, SuiAddress},

async fn main() -> Result<(), anyhow::Error> {
    let sui = SuiClient::new("", None, None).await?;
    // Load keystore from ~/.sui/sui_config/sui.keystore
    let keystore_path = match dirs::home_dir() {
        Some(v) => v.join(".sui").join("sui_config").join("sui.keystore"),
        None => panic!("Cannot obtain home directory path"),

    let my_address = SuiAddress::from_str("0x47722589dc23d63e82862f7814070002ffaaa465")?;
    let gas_object_id = ObjectID::from_str("0x273b2a83f1af1fda3ddbc02ad31367fcb146a814")?;
    let recipient = SuiAddress::from_str("0xbd42a850e81ebb8f80283266951d4f4f5722e301")?;

    // Create a sui transfer transaction
    let transfer_tx = sui
        .transfer_sui(my_address, gas_object_id, 1000, recipient, Some(1000))

    // Sign transaction
    let keystore = Keystore::from(FileBasedKeystore::new(&keystore_path)?);
    let signature = keystore.sign_secure(&my_address, &transfer_tx, Intent::default())?;
    // Execute the transaction
    let transaction_response = sui
        .execute_transaction(Transaction::from_data(transfer_tx, Intent::default(), signature))

    println!("{:?}", transaction_response);


Example 3 - Event subscription

Use the WebSocket client to subscribe to events.

use futures::StreamExt;
use sui_sdk::rpc_types::SuiEventFilter;
use sui_sdk::SuiClient;

async fn main() -> Result<(), anyhow::Error> {
    let sui = SuiClient::new("", Some("ws://"), None).await?;
    let mut subscribe_all = sui.event_api().subscribe_event(SuiEventFilter::All(vec![])).await?;
    loop {

Note: You will need to connect to a fullnode for the Event subscription service, see Full node setup if you want to run a Sui Fullnode.

Larger examples

See the Sui Rust SDK README for the Tic Tac Toe example.

Last update 12/9/2022, 7:13:30 PM