Skip to main content

Send a Micro Transaction

If you need to send an amount below the minimum storage deposit, you should use a microtransaction.

Online Faucet

You can request test funds from the Shimmer Testnet Faucet.

Code Example

The following example will:

  1. Create an account manager.
  2. Get Alice's account which was created in the first guide.
  3. Create the outputs for a microtransaction.
  4. Send the micro-microtransaction using the Account.send_micro_transaction(addresses_with_micro_amount, options) function.
Dotenv

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

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

//! cargo run --example send_micro_transaction --release
// In this example we will send an amount below the minimum storage deposit
// Rename `.env.example` to `.env` first

use std::env;

use dotenv::dotenv;
use iota_wallet::{account_manager::AccountManager, AddressWithMicroAmount, Result};

#[tokio::main]
async fn main() -> Result<()> {
// This example uses dotenv, which is not safe for use in production
dotenv().ok();

// Create the account manager
let manager = AccountManager::builder().finish().await?;

// Get the account we generated with `01_create_wallet`
let account = manager.get_account("Alice").await?;

// Set the stronghold password
manager
.set_stronghold_password(&env::var("STRONGHOLD_PASSWORD").unwrap())
.await?;

let outputs = vec![AddressWithMicroAmount {
address: "rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu".to_string(),
amount: 1,
return_address: None,
expiration: None,
}];

let transaction = account.send_micro_transaction(outputs, None).await?;

println!(
"Transaction: {} Block sent: {}/api/core/v2/blocks/{}",
transaction.transaction_id,
&env::var("NODE_URL").unwrap(),
transaction.block_id.expect("no block created yet")
);

Ok(())
}

Run the Example

Run the example by running the following command:

cargo run --example send_micro_transaction --release

Expected Output

Transaction: 0x78abf6499023396fa9510155237542500015da882e2676bc9e5cd8280e3c15e6
Block sent: http://localhost:14265/api/core/v2/blocks/0xe601e25316c17c9aaa19de881aacd55ac270bc99697d34c4a9f4e57edf10cbe2