Skip to content

Commit

Permalink
update rust sdk docs (MystenLabs#4317)
Browse files Browse the repository at this point in the history
Co-authored-by: songxuexian <songxuexian@hnnewsoft.com>
  • Loading branch information
bitstory and songxuexian authored Aug 29, 2022
1 parent 1cd5ce9 commit a90f76f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions doc/src/build/rust-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Interact with Sui over Rust SDK
## Overview
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](../build/devnet.md) and [Sui Full Node](fullnode.md).

The [`SuiClient`](cli-client.md) can be used to create an HTTP (`SuiClient::new_http_client`) or a WebSocket client(`SuiClient::new_ws_client`).
The [`SuiClient`](cli-client.md) can be used to create an HTTP or a WebSocket client (`SuiClient::new_rpc_client`).
See our [JSON-RPC](json-rpc.md#sui-json-rpc-methods) doc for the list of available methods.

> 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.
Expand Down Expand Up @@ -43,9 +43,9 @@ use sui_sdk::SuiClient;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let sui = SuiClient::new_http_client("https://gateway.devnet.sui.io:443")?;
let sui = SuiClient::new_rpc_client("https://gateway.devnet.sui.io:443", None).await?;
let address = SuiAddress::from_str("0xec11cad080d0496a53bafcea629fcbcfff2a9866")?;
let objects = sui.get_objects_owned_by_address(address).await?;
let objects = sui.read_api().get_objects_owned_by_address(address).await?;
println!("{:?}", objects);
Ok(())
}
Expand All @@ -71,7 +71,7 @@ use sui_sdk::{

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let sui = SuiClient::new_http_client("https://gateway.devnet.sui.io:443")?;
let sui = SuiClient::new_rpc_client("https://gateway.devnet.sui.io:443", 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"),
Expand All @@ -84,18 +84,20 @@ async fn main() -> Result<(), anyhow::Error> {

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

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

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

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

Expand All @@ -116,8 +118,8 @@ use sui_sdk::SuiClient;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let sui = SuiClient::new_ws_client("ws://127.0.0.1:9001").await?;
let mut subscribe_all = sui.subscribe_event(SuiEventFilter::All(vec![])).await?;
let sui = SuiClient::new_rpc_client("https://gateway.devnet.sui.io:443", Some("ws://127.0.0.1:9001")).await?;
let mut subscribe_all = sui.event_api().subscribe_event(SuiEventFilter::All(vec![])).await?;
loop {
println!("{:?}", subscribe_all.next().await);
}
Expand Down

0 comments on commit a90f76f

Please sign in to comment.