From 36496a519aea59fb5f2a8d752aa3aea72f7cafa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Wed, 11 Jan 2023 00:13:45 +0100 Subject: [PATCH] rust-sdk: add additinal example --- .../examples/simple_but_manually_connect.rs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 sdk/rust/nym-sdk/examples/simple_but_manually_connect.rs diff --git a/sdk/rust/nym-sdk/examples/simple_but_manually_connect.rs b/sdk/rust/nym-sdk/examples/simple_but_manually_connect.rs new file mode 100644 index 0000000000..0d79556dfd --- /dev/null +++ b/sdk/rust/nym-sdk/examples/simple_but_manually_connect.rs @@ -0,0 +1,27 @@ +use nym_sdk::mixnet; + +#[tokio::main] +async fn main() { + logging::setup_logging(); + + // Create client builder, including ephemeral keys. The builder can be usable in the context + // where you don't want to connect just yet + let client = mixnet::ClientBuilder::new(None, None).unwrap(); + + // Now we connect to the mixnet, using ephemeral keys already created + let mut client = client.connect_to_mixnet().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 throught the mixnet to ourselves + client + .send_str(&our_address.to_string(), "hello there") + .await; + + println!("Waiting for message"); + client + .on_messages(|msg| println!("Received: {}", String::from_utf8_lossy(&msg.message))) + .await; +}