# Setting up Rust environment errors

**URL:** https://forums.sui.io/t/setting-up-rust-environment-errors/44805
**Category:** SDK
**Created:** [June 26, 2023, 5:54pm UTC](https://forums.sui.io/t/setting-up-rust-environment-errors/44805 "2023-06-26T17:54:05Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![EliteIntegrity](https://avatars.discourse-cdn.com/v4/letter/e/90ced4/32.png) [@EliteIntegrity](https://forums.sui.io/u/EliteIntegrity)
#### Post date: [June 26, 2023, 5:54pm UTC](https://forums.sui.io/t/setting-up-rust-environment-errors/44805/1 "2023-06-26T17:54:05Z")

</div>

Hi,

I am trying the most basic Rust example to interact with the network here. [sui/crates/sui-sdk/examples/get\_owned\_objects.rs at main · MystenLabs/sui · GitHub](https://github.com/MystenLabs/sui/blob/main/crates/sui-sdk/examples/get_owned_objects.rs)

I have added:

```auto
[dependencies]
sui-sdk = { git = "https://github.com/MystenLabs/sui" }

```

to Cargo.toml. Installed LLVM, protoc.exe. When I run Cargo build I get the following errors:

PS D:\Rust Projects\> cargo build  
error: could not find `Cargo.toml` in `D:\Rust Projects` or any parent directory  
PS D:\Rust Projects\> cd my\_test  
PS D:\Rust Projects\my\_test\> cargo build  
Compiling my\_test v0.1.0 (D:\Rust Projects\my\_test)  
error[E0432]: unresolved import `sui_json_rpc_types`  
 → src\main.rs:5:5  
|  
5 | use sui\_json\_rpc\_types::{SuiObjectDataOptions, SuiObjectResponseQuery};  
| ^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `sui_json_rpc_types`

error[E0433]: failed to resolve: use of undeclared crate or module `tokio`  
 → src\main.rs:9:3  
|  
9 | #[tokio::main]  
| ^^^^^ use of undeclared crate or module `tokio`

error[E0433]: failed to resolve: use of undeclared crate or module `anyhow`  
 → src\main.rs:10:31  
|  
10 | async fn main() → Result\<(), anyhow::Error\> {  
| ^^^^^^ use of undeclared crate or module `anyhow`

error[E0752]: `main` function is not allowed to be `async`  
 → src\main.rs:10:1  
|  
10 | async fn main() → Result\<(), anyhow::Error\> {  
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `main` function is not allowed to be `async`

Some errors have detailed explanations: E0432, E0433, E0752.  
For more information about an error, try `rustc --explain E0432`.  
error: could not compile `my_test` (bin “my\_test”) due to 4 previous errors  
PS D:\Rust Projects\my\_test\>

I am using Windows 10 and VS Code. I would be very grateful if someone knows what they mean and what I need to do. Many thanks in advance.

---

<div class="post-metadata">

### Author: ![EliteIntegrity](https://avatars.discourse-cdn.com/v4/letter/e/90ced4/32.png) [@EliteIntegrity](https://forums.sui.io/u/EliteIntegrity)
#### Post date: [June 27, 2023, 9:51am UTC](https://forums.sui.io/t/setting-up-rust-environment-errors/44805/2 "2023-06-27T09:51:52Z")

</div>

I have fixed three of the errors by adding two more lines to the dependencies section of Cargo.toml.

```auto
tokio = { version = "1", features = ["full"] }
anyhow = "1

```

I still have the following error.

```auto
use sui_json_rpc_types::{SuiObjectDataOptions, SuiObjectResponseQuery};
  | ^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `sui_json_rpc_types`

```

I can see the sui\_json\_rpc\_types crate in the list of crates with all the rest here: [Index of crates](https://mystenlabs.github.io/sui/)

Anyone who can tell me what I am doing wrong will be placed forever in a special place in my heart. Thanks.

---

<div class="post-metadata">

### Author: ![csknk](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@csknk](https://forums.sui.io/u/csknk)
#### Post date: [July 27, 2023, 9:06am UTC](https://forums.sui.io/t/setting-up-rust-environment-errors/44805/3 "2023-07-27T09:06:59Z")

</div>

I’m stuck at exactly the same point.

Did you manage to get the example working?

---

<div class="post-metadata">

### Author: ![EliteIntegrity](https://avatars.discourse-cdn.com/v4/letter/e/90ced4/32.png) [@EliteIntegrity](https://forums.sui.io/u/EliteIntegrity)
#### Post date: [July 27, 2023, 5:42pm UTC](https://forums.sui.io/t/setting-up-rust-environment-errors/44805/4 "2023-07-27T17:42:23Z")

</div>

I did but I can’t remember what it was and I uninstalled and deleted everything. I got it to compile and run and got some unfathomable error at runtime. Couldn’t get help on discord, nothing on Google. Every single example I tried had multiple errors which is why I gave up. I am working on my game and I will come back or try another network in a year or so when the technology and the user base has matured and grown. The best Rust help I found was chat gpt although it knows nothing of Sui speciffically, it solved some rust issues. Sorry I don’t have the answer. I did get some smart contracts published via the web based compiler/deployer but interacting with them or creating a wallet completley eluded me.

---

<div class="post-metadata">

### Author: ![csknk](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@csknk](https://forums.sui.io/u/csknk)
#### Post date: [July 27, 2023, 5:50pm UTC](https://forums.sui.io/t/setting-up-rust-environment-errors/44805/5 "2023-07-27T17:50:04Z")

</div>

Thanks for the reply!

Very frustrating that the basic examples don’t work…

I finally got the basic “get objects owned by an address” working, adding here in case others stumble upon this post:

```rust
use serde_json::{json, Value};
use std::str::FromStr;
use sui_sdk::rpc_types::{Page, SuiObjectDataOptions, SuiObjectResponse, SuiObjectResponseQuery};
use sui_sdk::types::base_types::{ObjectID, SuiAddress};
use sui_sdk::SuiClientBuilder;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
    let address_string = "0xe85738f9cb22cf80f77b861a9e9aca13c0a297cf0f1c075d35a9b3fb94bf6f89";
    let sui = SuiClientBuilder::default()
        .build("https://fullnode.mainnet.sui.io:443")
        .await?;
    let address = SuiAddress::from_str(address_string)?;
    let objects = sui
        .read_api()
        .get_owned_objects(
            address,
            Some(SuiObjectResponseQuery::new_with_options(
                SuiObjectDataOptions::full_content(),
            )),
            None,
            None,
        )
        .await?;
    let _ = pretty_print_objects(objects);
    Ok(())
}

fn pretty_print_objects(objects: Page<SuiObjectResponse, ObjectID>) -> Result<(), anyhow::Error> {
    let mut json_array: Vec<Value> = Vec::new();
    for object in objects.data {
        let value = object.data.unwrap();
        let json_object: Value = json!({
            "id": value.object_id,
            "digest": value.digest,
        });
        json_array.push(json_object);
    }
    let json_string = serde_json::to_string(&json_array).unwrap();
    println!("{}", json_string);
    Ok(())
}

```
