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 Gateway and Sui Full Node.

The SuiClient can be used to create an HTTP (SuiClient::new_http_client) or a WebSocket client(SuiClient::new_ws_client).
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_http_client("")?;
    let address = SuiAddress::from_str("0xec11cad080d0496a53bafcea629fcbcfff2a9866")?;
    let objects = sui.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 Gateway.

Example 2 - Create and execute transaction

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

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

async fn main() -> Result<(), anyhow::Error> {
    let sui = SuiClient::new_http_client("")?;
    // 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))

    // Get signer from keystore
    let keystore = SuiKeystore::load_or_create(&keystore_path)?;
    let signer = keystore.signer(my_address);

    // Sign the transaction
    let signature = Signature::new(&transfer_tx, &signer);

    // Execute the transaction
    let transaction_response = sui
        .execute_transaction(Transaction::new(transfer_tx, signature))

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


Example 3 - Event subscription

Use the 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_ws_client("ws://").await?;
    let mut subscribe_all = sui.subscribe_event(SuiEventFilter::All(vec![])).await?;
    loop {

Note: You will need to connect to a fullnode for the Event subscription service, see Fullnode 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 8/6/2022, 2:44:52 AM