d07f9c8fad
* rework of sdk docs * update integration docs + bit of overall restructure * remove debug logger from tool
38 lines
1.2 KiB
Plaintext
38 lines
1.2 KiB
Plaintext
# Simple Send
|
|
|
|
import { Callout } from 'nextra/components'
|
|
|
|
Lets look at a very simple example of how you can import and use the websocket client in a piece of Rust code.
|
|
|
|
Simply importing the `nym_sdk` crate into your project allows you to create a client and send traffic through the mixnet.
|
|
|
|
> You can find this code [here](https://github.com/nymtech/nym/blob/master/sdk/rust/nym-sdk/examples/simple.rs)
|
|
|
|
```rust
|
|
use nym_sdk::mixnet;
|
|
use nym_sdk::mixnet::MixnetMessageSender;
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
nym_bin_common::logging::setup_logging();
|
|
|
|
// Passing no config makes the client fire up an ephemeral session and figure shit out on its own
|
|
let mut client = mixnet::MixnetClient::connect_new().await.unwrap();
|
|
|
|
// Be able to get our client address
|
|
let our_address = client.nym_address();
|
|
println!("Our client nym address is: {our_address}");
|
|
|
|
// Send a message through the mixnet to ourselves
|
|
client
|
|
.send_plain_message(*our_address, "hello there")
|
|
.await
|
|
.unwrap();
|
|
|
|
println!("Waiting for message (ctrl-c to exit)");
|
|
client
|
|
.on_messages(|msg| println!("Received: {}", String::from_utf8_lossy(&msg.message)))
|
|
.await;
|
|
}
|
|
```
|