diff --git a/doc/src/build/rust-sdk.md b/doc/src/build/rust-sdk.md index 527a27dc3b788..60b6bef05ecb4 100644 --- a/doc/src/build/rust-sdk.md +++ b/doc/src/build/rust-sdk.md @@ -3,25 +3,39 @@ title: Sui Rust SDK --- ## Overview -The Sui SDK is a collection of rust JSON-RPC wrapper and crypto utilities that you can use to interact with the Sui Gateway and Sui Full Node. -The `SuiClient` can be used to create a http(`SuiClient::new_http_client`) or a websocket client(`SuiClient::new_ws_client`). -See [JSON-RPC doc](json-rpc.md#sui-json-rpc-methods) for list of available methods. +The [Sui SDK](https://github.com/MystenLabs/sui/tree/main/crates/sui-sdk) is a collection of Rust language JSON-RPC wrapper and crypto utilities you can use to interact with the [Sui Devnet Gateway](../explore/devnet.md) and [Sui Full Node](fullnode.md). -> Note: As of v0.6.0, the web socket client is for subscription only, please use http client for other api methods. +The [`SuiClient`](cli-client.md) can be used to create an HTTP (`SuiClient::new_http_client`) or a WebSocket client(`SuiClient::new_ws_client`). +See our [JSON-RPC](json-rpc.md#sui-json-rpc-methods) doc for the list of available methods. -## Examples -Add the sui-sdk crate in your Cargo.toml: +> Note: As of [Sui version 0.6.0](https://github.com/MystenLabs/sui/releases/tag/devnet-0.6.0), the WebSocket client is for [subscription only](pubsub.md); use the HTTP client for other API methods. + +## References + +Find the `rustdoc` output for key Sui projects at: + +* Sui blockchain - https://mystenlabs.github.io/sui/ +* Narwhal and Tusk consensus engine - https://mystenlabs.github.io/narwhal/ +* Mysten Labs infrastructure - https://mystenlabs.github.io/mysten-infra/ + +## Configuration +Add the `sui-sdk` crate in your [`Cargo.toml`](https://doc.rust-lang.org/cargo/reference/manifest.html) file like so: ```toml [dependencies] sui-sdk = { git = "https://github.com/MystenLabs/sui" } ``` -Use the devnet branch if you are connecting to the devnet. +If you are connecting to the devnet, use the `devnet` branch instead: ```toml [dependencies] sui-sdk = { git = "https://github.com/MystenLabs/sui", branch = "devnet" } ``` +## Examples + ### Example 1 - Get all objects owned by an address + +This will print a list of object summaries owned by the address `"0xec11cad080d0496a53bafcea629fcbcfff2a9866"`: + ```rust use std::str::FromStr; use sui_sdk::types::base_types::SuiAddress; @@ -36,10 +50,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } ``` -This will print a list of object summaries owned by the address "0xec11cad080d0496a53bafcea629fcbcfff2a9866". -You can verify the result with the [Sui explorer](https://explorer.devnet.sui.io/) if you are using the Sui devnet. + +You can verify the result with the [Sui Explorer](https://explorer.devnet.sui.io/) 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: + ```rust use std::str::FromStr; use sui_sdk::crypto::{Keystore, SuiKeystore}; @@ -85,6 +102,9 @@ async fn main() -> Result<(), anyhow::Error> { ``` ### Example 3 - Event subscription + +Use the the WebSocket client to [subscribe to events](pubsub.md). + ```rust use futures::StreamExt; use sui_sdk::rpc_types::SuiEventFilter; @@ -99,8 +119,9 @@ async fn main() -> Result<(), anyhow::Error> { } } ``` -> Note: You will need to connect to a fullnode for the Event subscription service, see [Fullnode setup](fullnode.md#fullnode-setup) if you want to run a fullnode. +> Note: You will need to connect to a fullnode for the Event subscription service, see [Fullnode setup](fullnode.md#fullnode-setup) if you want to run a Sui Fullnode. + +## Larger examples -## Larger Examples -[Tic Tac Toe](../../../crates/sui-sdk/README.md) \ No newline at end of file +See the Sui Rust SDK README for the [Tic Tac Toe](https://github.com/MystenLabs/sui/tree/main/crates/sui-sdk) example.