Send a Signed Transaction
A SignedTransaction is a core payload type that is used to send value-based messages as Unspent Transaction Output (UTXO). This core payload changes the ledger state as it spends "old" outputs and replaces them with new outputs.
Though it is possible to send transactions with iota.rs, we strongly recommend that you use the official
wallet.rs
library together with the
stronghold.rs
enclave for value-based transfers. This combination
incorporates the best security practices while dealing with seeds, related addresses, and UTXO
.
- Java
- Nodejs
- Python
- Rust
- Wasm
Sending value-based messages is a very straightforward process if you use the
ClientMessageBuilder
helper class. You will only need to
provide a valid seed by chaining a call to
.withSeed(seed: String)
, and output addresses
and amount by chaining a call to
withOutput(address: String, amount: long):
.
The method will find valid output(s) that can be used to fund the given amount(s) and the unspent amount will be sent to
the same address.
public static void transaction() {
Client iota = node();
String seed_1 = "NONSECURE_USE_OF_DEVELOPMENT_SEED_1";
Message message = iota
.message()
.withSeed(seed_1)
// Insert the output address and amount to spent. The amount cannot be zero.
.withOutput(
// We generate an address from our seed so that we send the funds to ourselves
iota.getAddresses(seed_1).withRange(0, 1).finish()[0], 1000000
).finish();
System.out.println("Transaction sent: https://explorer.iota.org/devnet/message/" + message.id());
}
Sending value-based messages is a very straightforward process if you use the
MessageSender
helper class. You will only need to provide a valid
seed by chaining a call to .seed(seed: string)
, and an
output address and amount by chaining a call to
.output(address: string, amount: string)
. The
method will find valid output(s) that can be used to fund the given amount(s) and the unspent amount will be sent to the
same address.
async function run() {
const {
ClientBuilder
} = require('@iota/client');
// Get the seed from environment variable
const IOTA_SEED_SECRET = process.env.IOTA_SEED_SECRET;
// client will connect to testnet by default
const client = new ClientBuilder().build();
const message = await client.message()
.seed(IOTA_SEED_SECRET)
.output('atoi1qqydc70mpjdvl8l2wyseaseqwzhmedzzxrn4l9g2c8wdcsmhldz0ulwjxpz', 1000000)
.submit();
console.log(message);
}
run()
Sending value-based messages is a very straightforward process. You will only need to provide a valid seed
, outputs
(addresses and amounts) parameters to the
Client.message()
function. The method will find valid output(s) that can be used to fund the given amount(s) and the remaining amount will
be sent back the input address.
import os
import iota_client
# Get the seed from environment variable
IOTA_SEED_SECRET = os.getenv('IOTA_SEED_SECRET')
if not IOTA_SEED_SECRET:
raise Exception("Please define environment variable called `IOTA_SEED_SECRET`")
client = iota_client.Client()
message = client.message(
seed=IOTA_SEED_SECRET,
outputs=[
{
'address': 'atoi1qqydc70mpjdvl8l2wyseaseqwzhmedzzxrn4l9g2c8wdcsmhldz0ulwjxpz',
'amount': 1_000_000
}
]
)
print(message)
Sending value-based messages is a very straightforward process if you use the
ClientMessageBuilder
helper
class. You will only need to provide a valid seed by chaining a call to
.with_seed(seed: &'a Seed)
, and
output address and amount by chaining a call to
.with_output(address: &str, amount: u64)
.
The method will find valid output(s) that can be used to fund the given amount(s) and the unspent amount will be sent to
the same address.
// Copyright 2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
//! cargo run --example 09_transaction --release
use iota_client::{Client, Result, Seed};
extern crate dotenv;
use dotenv::dotenv;
use std::env;
/// In this example we will send a transaction
#[tokio::main]
async fn main() -> Result<()> {
let iota = Client::builder()
.with_node("https://api.lb-0.h.chrysalis-devnet.iota.cafe")?
.finish()
.await?;
// This example uses dotenv, which is not safe for use in production
// Configure your own seed in ".env". Since the output amount cannot be zero, the seed must contain non-zero balance
dotenv().ok();
let seed_1 = Seed::from_bytes(&hex::decode(env::var("NONSECURE_USE_OF_DEVELOPMENT_SEED_1").unwrap())?);
let message = iota
.message()
.with_seed(&seed_1)
// Insert the output address and amount to spent. The amount cannot be zero.
.with_output(
// We generate an address from our seed so that we send the funds to ourselves
&iota.get_addresses(&seed_1).with_range(1..2).finish().await?[0],
1_000_000,
)?
.finish()
.await?;
println!(
"Transaction sent: https://explorer.iota.org/devnet/message/{}",
message.id().0
);
Ok(())
}
Sending value-based messages is a very straightforward process if you use the
MessageBuilder
helper class. You will only need to provide a valid seed by chaining a call to
.seed(seed: string)
and
an output address and amount by chaining a call to .output(address: string, amount: BigInt)
. The method will find valid
output(s) that can be used to fund the given amount(s) and the unspent amount will be sent to the same address.
async function run() {
const { ClientBuilder } = require('../node')
// Get the seed from environment variable
const IOTA_SEED_SECRET = process.env.IOTA_SEED_SECRET;
// client will connect to testnet by default
const client = await new ClientBuilder().build();
const message = await client.message()
.seed(IOTA_SEED_SECRET)
.output('atoi1qqydc70mpjdvl8l2wyseaseqwzhmedzzxrn4l9g2c8wdcsmhldz0ulwjxpz', BigInt(1000000))
.submit();
console.log(message);
}
run()
Due to the dust protection mechanism implemented in the network protocol, microtransactions below 1Mi of IOTA tokens can only be sent to another address if there is already at least 1Mi on that address
That's why the code in the example sent 1Mi, to comply with the protection.