Skip to main content

Send a Transaction

Though it is possible to send transactions with, we strongly recommend that you use the official library together with the enclave for value-based transfers. This combination incorporates the best security practices while dealing with seeds, related addresses, and UTXO.

The following code example will:

  1. Create a Client which will connect to the Shimmer Testnet.
  2. Create a SecretManager from a mnemonic.
  3. Generate a public address.
  4. Build and post a block with an output address and amount to send.
  5. Log the transaction.

You can also find this guide in the native iota.js library

Code Example


This example uses dotenv, which is not safe to use in production environments.

// Copyright 2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

//! In this example we will send a transaction.
//! Run: `cargo run --example transaction --release`.

use iota_client::{secret::SecretManager, Client, Result};

async fn main() -> Result<()> {
// This example uses dotenv, which is not safe for use in production
// Configure your own mnemonic in ".env". Since the output amount cannot be zero, the mnemonic must contain non-zero
// balance

let node_url = std::env::var("NODE_URL").unwrap();

let client = Client::builder().with_node(&node_url)?.finish()?;

let secret_manager =

let block = client
// Insert the output address and amount to spent. The amount cannot be zero.
// We generate an address from our own mnemonic so that we send the funds to ourselves


"Transaction sent: {}/block/{}",


Run the Example

Run the example by running the following command:

cargo run --example transaction --release

Expected Output

Transaction sent: