1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! Using `MixnetClientBuilder` with ephemeral (in-memory) keys.
//!
//! The builder lets you configure the client before connecting.
//! Ephemeral keys are generated in memory and discarded on disconnect.
//!
//! Run with: cargo run --example builder
use nym_sdk::mixnet;
use nym_sdk::mixnet::MixnetMessageSender;
#[tokio::main]
async fn main() {
nym_bin_common::logging::setup_tracing_logger();
// Create a builder with ephemeral keys.
// The builder lets you configure the client before connecting.
let client = mixnet::MixnetClientBuilder::new_ephemeral()
.build()
.unwrap();
// Connect to the mixnet.
let mut client = client.connect_to_mixnet().await.unwrap();
let our_address = client.nym_address();
println!("Our client nym address is: {our_address}");
// Send a message and wait for it.
client
.send_plain_message(*our_address, "hello there")
.await
.unwrap();
println!("Waiting for message");
if let Some(received) = client.wait_for_messages().await {
for r in received {
println!("Received: {}", String::from_utf8_lossy(&r.message));
}
}
// Always disconnect for clean shutdown.
client.disconnect().await;
}