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
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
//! cargo run --example create_alias --release
// In this example we will create an alias output
// Rename `.env.example` to `.env` first
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: {} Block sent: {}/api/core/v2/blocks/{}",
transaction.transaction_id,
&env::var("NODE_URL").unwrap(),
transaction.block_id.expect("no block created yet")
);
Ok(())
}