Coconut credential generation

The following code shows how you can use the SDK to create and use a credential representing paid bandwidth on the Sandbox testnet.

use futures::StreamExt;
use nym_network_defaults::setup_env;
use nym_sdk::mixnet;
use nym_sdk::mixnet::MixnetMessageSender;

async fn main() -> anyhow::Result<()> {
    // right now, only sandbox has coconut setup
    // this should be run from the `sdk/rust/nym-sdk` directory

    let sandbox_network = mixnet::NymNetworkDetails::new_from_env();
    let mnemonic = String::from("my super secret mnemonic");

    let mixnet_client = mixnet::MixnetClientBuilder::new_ephemeral()

    let bandwidth_client = mixnet_client.create_bandwidth_client(mnemonic)?;

    // Get a bandwidth credential worth 1000000 unym for the mixnet_client

    // Connect using paid bandwidth credential
    let mut client = mixnet_client.connect_to_mixnet().await?;

    let our_address = client.nym_address();

    // Send a message throughout the mixnet to ourselves
        .send_plain_message(*our_address, "hello there")

    println!("Waiting for message");
    let received =;
    println!("Received: {}", String::from_utf8_lossy(&received.message));


You can read more about Coconut credentials (also referred to as zk-Nym) here.