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:
- Create an account manager.
- Get Alice's account which was created in the first guide.
- Create the outputs for a microtransaction.
- Send the micro-microtransaction using the
Account.send_micro_transaction(addresses_with_micro_amount, options)
function.
- Rust
- Nodejs
- Python
- Java
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 by running the following command:
cargo run --example send_micro_transaction --release
/**
* This example sends IOTA micro transactions to an address.
*/
const getUnlockedManager = require('./account-manager');
async function run() {
try {
const manager = await getUnlockedManager();
const account = await manager.getAccount('Alice');
await account.sync();
//TODO: Replace with the address of your choice!
const address =
'rms1qrrv7flg6lz5cssvzv2lsdt8c673khad060l4quev6q09tkm9mgtupgf0h0';
const amount = '1000';
const response = await account.sendMicroTransaction([
{
address,
amount,
},
]);
console.log(response);
console.log(
`Check your block on ${process.env.NODE_URL}/api/core/v2/blocks/${response.blockId}`,
);
} catch (error) {
console.log('Error: ', error);
}
process.exit(0);
}
run();
You can run the example by running the following command from the wallet/bindings/nodejs/examples/
folder:
node 4c-send-micro-transaction.js
from iota_wallet import IotaWallet
# In this example we will send an amount below the minimum storage deposit
wallet = IotaWallet('./alice-database')
account = wallet.get_account('Alice')
# Sync account with the node
response = account.sync()
print(f'Synced: {response}')
wallet.set_stronghold_password("some_hopefully_secure_password")
outputs = [{
"address": "rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu",
"amount": "1",
}]
transaction = account.send_micro_transaction(outputs, None)
print(f'Sent transaction: {transaction}')
You can run the example by running the following command from the binding/python/examples
folder:
python3 4-send-micro-transaction.py
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
import org.iota.Wallet;
import org.iota.types.*;
import org.iota.types.account_methods.SyncAccount;
import org.iota.types.exceptions.InitializeWalletException;
import org.iota.types.exceptions.WalletException;
import org.iota.types.ids.account.AccountAlias;
import org.iota.types.secret.StrongholdSecretManager;
public class SendMicroTransaction {
public static void main(String[] args) throws WalletException, InterruptedException, InitializeWalletException {
// This example assumes that a wallet has already been created using the ´SetupWallet.java´ example.
// If you haven't run the ´SetupWallet.java´ example yet, you must run it first to be able to load the wallet as shown below:
Wallet wallet = new Wallet(new WalletConfig()
.withClientOptions(new ClientConfig().withNodes(Env.NODE))
.withSecretManager(new StrongholdSecretManager(Env.STRONGHOLD_PASSWORD, null, Env.STRONGHOLD_VAULT_PATH))
.withCoinType(CoinType.Shimmer)
.withStoragePath(Env.STORAGE_PATH)
);
// Get account and sync it with the registered node to ensure that its balances are up-to-date.
AccountHandle a = wallet.getAccount(new AccountAlias(Env.ACCOUNT_NAME));
a.syncAccount(new SyncAccount().withOptions(new SyncOptions()));
// Fund the account for this example.
ExampleUtils.fundAccount(a);
// TODO: replace with your own values.
String receiverAddress = a.getPublicAddresses()[0].getAddress();
String amount = "1";
// Configure outputs
Transaction t = a.sendMicroTransaction(new org.iota.types.account_methods.SendMicroTransaction().withAddressesWithMicroAmount(new AddressWithMicroAmount[]{new AddressWithMicroAmount()
.withAddress(receiverAddress)
.withAmount(amount)
}));
// Print transaction
System.out.println(t);
// In case you are done and don't need the wallet instance anymore you can destroy the instance to clean up memory.
// For this, check out the ´DestroyWallet.java´ example.
}
}
Expected Output
- Rust
- Nodejs
- Python
- Java
Transaction: 0x78abf6499023396fa9510155237542500015da882e2676bc9e5cd8280e3c15e6
Block sent: http://localhost:14265/api/core/v2/blocks/0xe601e25316c17c9aaa19de881aacd55ac270bc99697d34c4a9f4e57edf10cbe2
{
payload: {
type: 6,
essence: {
type: 1,
networkId: '1856588631910923207',
inputs: [Array],
inputsCommitment: '0xad0e11ab7795212f3ff497e06c22218a18b297280e26e1d6392d217244879348',
outputs: [Array]
},
unlocks: [ [Object] ]
},
blockId: '0x20cc5acd8af1a9d27b181632ef32818a721622ab0c9d887977b2f1501dd0ae42',
inclusionState: 'Pending',
timestamp: '1662654628971',
transactionId: '0x91a469ff1008ed3dc21d02aa6c20d8c2c048c5f096d7c9af797d3215f824e369',
networkId: '1856588631910923207',
incoming: false,
note: null
}
Check your block on http://localhost:14265/api/core/v2/blocks/0x20cc5acd8af1a9d27b181632ef32818a721622ab0c9d887977b2f1501dd0ae42
Synced:{
'baseCoin':{
'total':'3302280903',
'available':'3302280903'
},
'requiredStorageDeposit':'910393500',
'nativeTokens':[
{
'tokenId':'0x08b83d49922e341d2cb45159707cfafdc9dc8fdb9d119543480dbaa5773eed8c4a0100000000',
'total':'0x64',
'available':'0x64'
}
],
'nfts':[
'0xdc8be91d779aac048aa9001ab99ecf12cf62a4701185a95f6206a1a201bfbe7c',
'0x1b670afba8d59a445cbaf167f1fda05879362e3ea034f5c4a0979fbeb5a3964b',
'0x17f97185f80fa56eab974de6b7bbb80fa812d4e8e37090d166a0a41da129cebc',
'0x1e808b7c6e603aaeb5f718881a74fedae72981ac7d5f0294eb561cad0e653566',
'0xceae643ff7c112a3adce8f55f7953ba0707ade21256a7a09068c0b47f7c62c5b',
'0x77133189021f50d8d66e0678e553af9f46a832a24239653d3555edb8dc859e1f',
'0x3f0e11e9d9f48a57d0fba43d7d1158ee673cb8055f80a5ce45ad174c962c0d8a'
],
'aliases':[
],
'foundries':[
],
'potentiallyLockedOutputs':{
}
}
Sent transaction:{
'payload':{
'type':6,
'essence':{
'type':1,
'networkId':'1856588631910923207',
'inputs':[
{
'type':0,
'transactionId':'0x0220b5247654d05529f40b3d8cdb7ca6f89627038f47a68aa578b9e675ddc937',
'transactionOutputIndex':19
},
{
'type':0,
'transactionId':'0x0220b5247654d05529f40b3d8cdb7ca6f89627038f47a68aa578b9e675ddc937',
'transactionOutputIndex':20
}
],
'inputsCommitment':'0x106eac89e7db625c039af5193be5050a57c431e68d1c331bb323d36f0d4dc812',
'outputs':[
{
'type':3,
'amount':'50601',
'unlockConditions':[
{
'type':0,
'address':{
'type':0,
'pubKeyHash':'0x60200bad8137a704216e84f8f9acfe65b972d9f4155becb4815282b03cef99fe'
}
},
{
'type':1,
'returnAddress':{
'type':0,
'pubKeyHash':'0x8297ac4149c80cca8225e5f2da36df89a93cd2998d7f6d488c97250a881e65af'
},
'amount':'50600'
},
{
'type':3,
'returnAddress':{
'type':0,
'pubKeyHash':'0x8297ac4149c80cca8225e5f2da36df89a93cd2998d7f6d488c97250a881e65af'
},
'unixTime':1666003100
}
]
},
{
'type':3,
'amount':'50599',
'unlockConditions':[
{
'type':0,
'address':{
'type':0,
'pubKeyHash':'0x8297ac4149c80cca8225e5f2da36df89a93cd2998d7f6d488c97250a881e65af'
}
}
]
}
]
},
'unlocks':[
{
'type':0,
'signature':{
'type':0,
'publicKey':'0xe62838fda7e8b77bf80e49967f0f089ae2a7230547d5231649732952f6336fae',
'signature':'0xf232856bbbc386277820fa30db7ba0b151ff8eea162732001ab532b8650c800880ac2fc6f28cab74ca752a6cbfdc046e860f0a08e99355d0a71f6c18b1d15906'
}
},
{
'type':1,
'reference':0
}
]
},
'blockId':'0xfe42f0281946d1b5bdd8ad185c7849163a0f86c49a22300ea5fd4bb53afba258',
'inclusionState':'Pending',
'timestamp':'1665916700678',
'transactionId':'0x850c1e43dff1a28a42d71edc6d4ad0b9f251c03993f9b0684a34f645514ffe27',
'networkId':'1856588631910923207',
'incoming':False,
'note':None
}
{
"payload":{
"type":6,
"essence":{
"type":1,
"networkId":"1856588631910923207",
"inputs":[
{
"type":0,
"transactionId":"0xce5504e02bf0796e48143d5daa1753500e798dbab673e14bb671512750f7d03a",
"transactionOutputIndex":0
},
{
"type":0,
"transactionId":"0x27df04eac1408b4ec758f6aa222d616b21d9b237789e601d9d0b81aa6466fa97",
"transactionOutputIndex":2
}
],
"inputsCommitment":"0x01a6a0ee6942ce4fd0196c1d54db56eb44cd6b983505bede16b6b5b9d0b4f835",
"outputs":[
{
"type":3,
"amount":"50601",
"unlockConditions":[
{
"type":0,
"address":{
"type":0,
"pubKeyHash":"0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
},
{
"type":1,
"returnAddress":{
"type":0,
"pubKeyHash":"0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
},
"amount":"50600"
},
{
"type":3,
"returnAddress":{
"type":0,
"pubKeyHash":"0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
},
"unixTime":1664887368
}
]
},
{
"type":4,
"amount":"50300",
"aliasId":"0x429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef",
"stateIndex":10,
"stateMetadata":"0x",
"foundriesCounter":0,
"unlockConditions":[
{
"type":4,
"address":{
"type":0,
"pubKeyHash":"0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
},
{
"type":5,
"address":{
"type":0,
"pubKeyHash":"0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
}
]
},
{
"type":3,
"amount":"2096427899",
"nativeTokens":[
{
"id":"0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0100000000",
"amount":"0x3233"
},
{
"id":"0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0200000000",
"amount":"0x3233"
},
{
"id":"0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0400000000",
"amount":"0x17"
}
],
"unlockConditions":[
{
"type":0,
"address":{
"type":0,
"pubKeyHash":"0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
}
]
}
]
},
"unlocks":[
{
"type":0,
"signature":{
"type":0,
"publicKey":"0xde3152ce9d67415b9c5a042ea01caccc3f73ff1c0c77036874cb8badf9798d56",
"signature":"0x114f1c0ad726278b2d5167cb1b112529aa63cc0e3cf01c7936151f968050ff20a3d1385f708c36bd3761c38ddcba8ce735258ab5bd9cc1afa42510ddf6102e03"
}
},
{
"type":1,
"reference":0
}
]
},
"blockId":"0x8f9f12a968c32cc3d51e978f4de34252bc769ee7188e33a21f9351a7c1f122f3",
"inclusionState":"Pending",
"timestamp":"1664887369004",
"transactionId":"0xaccae1f4e78ee169d0fc1d99843e6cd417290da91aa62c696fa507d21fd245cc",
"networkId":"1856588631910923207",
"incoming":false
}