1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
//! In this example we will create an alias output.
//! Rename `.env.example` to `.env` first.
//!
//! `cargo run --example create_alias --release`
use std::env;
use iota_sdk::wallet::{Result, Wallet};
#[tokio::main]
async fn main() -> Result<()> {
// This example uses secrets in environment variables for simplicity which should not be done in production.
dotenvy::dotenv().ok();
// Create the wallet
let wallet = Wallet::builder().finish().await?;
// Get the account we generated with `01_create_wallet`
let account = wallet.get_account("Alice").await?;
account.sync(None).await?;
// Set the stronghold password
wallet
.set_stronghold_password(&env::var("STRONGHOLD_PASSWORD").unwrap())
.await?;
// Create an alias output
let transaction = account.create_alias_output(None, None).await?;
println!("Transaction sent: {}", transaction.transaction_id);
let block_id = account
.retry_transaction_until_included(&transaction.transaction_id, None, None)
.await?;
println!(
"Block included: {}/block/{}",
env::var("EXPLORER_URL").unwrap(),
block_id
);
Ok(())
}