Files
mfahampshire a70e68c7bd Max/smolmix docs (#6716)
* Smolmix documentation

* Add smolmix docs: landing page, tutorials, and developer page links

* Add Exit Gateway services page (NR vs IPR) and link from existing docs

* Update auto-generated command and API outputs

* Reorg of tutorials and architecture pages

* License information + remove TODO from docs.rs visibile comment + reorg
readme

* Add versions file for doc-wide versioning

* Relative -> absolute links

* Relative -> absolute links

* Update license + add old tutorial code as examples

* Streamline smolmix docs

* Clippy

* Clean up doc comments

* Last pass

* Add larger file download to list

* set new versions

* Clippy

* Remove blake pin from docs + add version range to root Cargo.toml

* Format example logging

* Remove crate blocked component

* Loose whitespace

* Add doc verification script for inline mdx

* Formatting

* Components regen

* Reorg + tighten text

* Voicing cohesion pass + remove bloated examples

* Voicing cont.

* Reduce max download size

* Small suggested clarifications

* Max/docs voicing consistency (#6769)

* Reduce max download size

* voicing consistency across docs

* New landing order w smolmix

* Tweaks

* Final tweaks
2026-05-13 11:19:44 +00:00

48 lines
1.7 KiB
Rust

//! Minimal message example: send a message to yourself and print it.
//!
//! Uses an ephemeral client: keys are generated in memory and discarded
//! on disconnect.
//!
//! ## What this demonstrates
//!
//! - `MixnetClient::connect_new()` creates an ephemeral client (ed25519 +
//! x25519 keypair, gateway selection, topology fetch, all automatic)
//! - `send_plain_message()` wraps the payload in Sphinx packets and queues
//! it for sending. Encryption and mixing happen in background tasks
//! - `on_messages()` drains the inbound queue fed by the gateway
//!
//! For persistent identity (same address across restarts), see
//! `builder_with_storage.rs`. For anonymous replies, see `surb_reply.rs`.
//!
//! ```sh
//! cargo run --example simple
//! ```
use nym_sdk::mixnet;
use nym_sdk::mixnet::MixnetMessageSender;
#[tokio::main]
async fn main() {
nym_bin_common::logging::setup_tracing_logger();
// Connect an ephemeral client (keys generated in memory).
let mut client = mixnet::MixnetClient::connect_new().await.unwrap();
let our_address = client.nym_address();
println!("Our client nym address is: {our_address}");
// Send a message to ourselves through the mixnet.
// The message is Sphinx-encrypted and routed through 5 nodes
// (gateway → 3 mix nodes → gateway).
client
.send_plain_message(*our_address, "hello there")
.await
.unwrap();
// Wait for incoming messages and print them.
// on_messages blocks forever. Press ctrl-c to exit.
println!("Waiting for message (ctrl-c to exit)");
client
.on_messages(|msg| println!("Received: {}", String::from_utf8_lossy(&msg.message)))
.await;
}