Skip to content

Commit

Permalink
[docs] Linking to crate docs and instruction on building locally (#15…
Browse files Browse the repository at this point in the history
…546)

## Description 

Linking to crate docs and instruction on building locally

## Test Plan 

Local

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes

---------

Co-authored-by: stefan-mysten <135084671+stefan-mysten@users.noreply.github.com>
  • Loading branch information
ronny-mysten and stefan-mysten authored Jan 4, 2024
1 parent 62bdd0f commit 9e910ee
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 20 deletions.
71 changes: 53 additions & 18 deletions crates/sui-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,51 @@ async fn main() -> Result<(), anyhow::Error> {

```

# Rust SDK examples
## Documentation for sui-sdk crate

[GitHub Pages](https://mystenlabs.github.io/sui/sui_sdk/index.html) 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, open a Terminal or Console to the `sui/crates/sui-sdk` directory:

1. Use the `rustup toolchain` command to install the `nightly` release channel.

```rust
rustup toolchain install nightly
```

1. Use the `rustup override` command to set the `nightly` release channel as active.

```rust
rustup override set nightly
```

1. Use `cargo doc` with the following `RUSTDOCFLAGS` set to build the documentation into the `sui/target` directory.

```rust
RUSTDOCFLAGS="--enable-index-page -Zunstable-options" cargo doc --no-deps
```

1. Open the `sui/target/doc/sui_sdk/index.html` file with a browser, like Chrome.

1. After building the docs, use the `rustup override` command again to return to the default toolchain.

```rust
rustup override unset
```

## Rust SDK examples

The [examples](https://github.com/MystenLabs/sui/tree/main/crates/sui-sdk/examples) folder provides both basic and advanced examples.

There are serveral files ending in `_api.rs` which provide code examples of the corresponding APIs and their methods. These showcase how to use the Sui Rust SDK, and can be run against the Sui testnet. Below are instructions on the prerequisites and how to run these examples.

## Prerequisites
### Prerequisites

Unless otherwise specified, most of these examples assume `Rust` and `cargo` are installed, and that there is an available internet connection. The examples connect to the Sui testnet (`https://fullnode.testnet.sui.io:443`) and execute different APIs using the active address from the local wallet. If there is no local wallet, it will create one, generate two addresses, set one of them to be active, and it will request 1 SUI from the testnet faucet for the active address.

## Running the existing examples
### Running the existing examples

In the root folder of the `sui` repository (or in the `sui-sdk` crate folder), you can individually run examples using the command `cargo run --example filename` (without `.rs` extension). For example:
* `cargo run --example sui_client` -- this one requires a local Sui network running (see [here](#Connecting to Sui Network
Expand All @@ -54,9 +88,9 @@ In the root folder of the `sui` repository (or in the `sui-sdk` crate folder), y
* `cargo run --example programmable_transactions_api`
* `cargo run --example sign_tx_guide`

## Basic Examples
### Basic Examples

### Connecting to Sui Network
#### Connecting to Sui Network
The `SuiClientBuilder` struct provides a connection to the JSON-RPC server that you use for all read-only operations. The default URLs to connect to the Sui network are:

- Local: http://127.0.0.1:9000
Expand Down Expand Up @@ -95,7 +129,7 @@ async fn main() -> Result<(), anyhow::Error> {
}
```

### Read the total coin balance for each coin type owned by this address
#### Read the total coin balance for each coin type owned by this address
```rust
use std::str::FromStr;
use sui_sdk::types::base_types::SuiAddress;
Expand Down Expand Up @@ -123,11 +157,9 @@ See the programmable transactions [example](https://github.com/MystenLabs/sui/bl

## Games examples

## Tic Tac Toe

### Demo quick start
### Tic Tac Toe quick start

#### 1. Prepare the environment
1. Prepare the environment
1. Install `sui` binary following the [Sui installation](https://github.com/MystenLabs/sui/blob/main/doc/src/build/install.md##install-sui-binaries) docs.
1. [Connect to Sui Devnet](https://github.com/MystenLabs/sui/blob/main/doc/src/build/connect-sui-network.md).
1. [Make sure you have two addresses with gas](https://github.com/MystenLabs/sui/blob/main/doc/src/build/cli-client.md#add-existing-accounts-to-clientyaml) by using the `new-address` command to create new addresses:
Expand All @@ -138,15 +170,16 @@ See the programmable transactions [example](https://github.com/MystenLabs/sui/bl
You can skip this step if you are going to play with a friend. :)
1. [Request Sui tokens](https://github.com/MystenLabs/sui/blob/main/doc/src/build/install.md#sui-tokens) for all addresses that will be used to join the game.

#### 2. Publish the move contract
2. Publish the move contract
1. [Download the Sui source code](https://github.com/MystenLabs/sui/blob/main/doc/src/build/install.md#source-code).
1. Publish the [`games` package](https://github.com/MystenLabs/sui/tree/main/sui_programmability/examples/games)
using the Sui client:
```shell
sui client publish --path /path-to-sui-source-code/sui_programmability/examples/games --gas-budget 10000
```
1. Record the package object ID.
#### 3. Create a new tic-tac-toe game

3. Create a new tic-tac-toe game
1. Run the following command in the Sui source code directory to start a new game, replacing the game package objects ID with the one you recorded:
```shell
cargo run --example tic-tac-toe -- --game-package-id <<games package object ID>> new-game
Expand All @@ -157,12 +190,14 @@ See the programmable transactions [example](https://github.com/MystenLabs/sui/bl
cargo run --example tic-tac-toe -- --game-package-id <<games package object ID>> new-game --player-x <<player X address>> --player-o <<player O address>>
```
1. Copy the game ID and pass it to your friend to join the game.
#### 4. Joining the game
Run the following command in the Sui source code directory to join the game, replacing the game ID and address accordingly:
```shell
cargo run --example tic-tac-toe -- --game-package-id <<games package object ID>> join-game --my-identity <<address>> --game-id <<game ID>>
```
4. Joining the game
Run the following command in the Sui source code directory to join the game, replacing the game ID and address accordingly:
```shell
cargo run --example tic-tac-toe -- --game-package-id <<games package object ID>> join-game --my-identity <<address>> --game-id <<game ID>>
```
## License
# License
[SPDX-License-Identifier: Apache-2.0](https://github.com/MystenLabs/sui/blob/main/LICENSE)
2 changes: 1 addition & 1 deletion docs/content/references/rust-sdk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ title: Sui Rust SDK
description: The Sui Rust SDK provides Rust wrappers around the Sui API. Using the SDK, you can interact with Sui networks using the Rust programming language.
---

The Sui Rust SDK crate is in the [**crates\sui-sdk** directory](https://github.com/MystenLabs/sui/tree/main/crates/sui-sdk) of the Sui repository.
The Sui Rust SDK crate is in the [**crates\sui-sdk** directory](https://github.com/MystenLabs/sui/tree/main/crates/sui-sdk) of the Sui repository.

{@include: ../../../crates/sui-sdk/README.md}
6 changes: 5 additions & 1 deletion docs/content/references/sui-sdks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ The Sui TypeScript SDK documentation is available in its own microsite: [Sui Typ

## Sui Rust SDK

See the [Rust SDK](https://github.com/MystenLabs/sui/tree/main/crates/sui-sdk) GitHub repository for SDK configuration and examples of using the Sui API with Rust.
See [Rust SDK](./rust-sdk.mdx) for SDK configuration and examples of using the Sui API with Rust.

### Crate documentation

[GitHub Pages](https://mystenlabs.github.io/sui/sui_sdk/index.html) hosts the generated documentation for Rust crates in the Sui repository.

0 comments on commit 9e910ee

Please sign in to comment.