forked from iotaledger/iota.rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
consolidation.rs
33 lines (25 loc) · 1.08 KB
/
consolidation.rs
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
// Copyright 2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
//! cargo run --example consolidation --release
use iota_client::{api::consolidate_funds, Client, Result, Seed};
extern crate dotenv;
use dotenv::dotenv;
use std::env;
/// In this example we will consolidate all funds in a range of addresses
#[tokio::main]
async fn main() -> Result<()> {
let address_range = 0..150;
// Create a client instance
let iota = Client::builder()
.with_node("https://api.lb-0.testnet.chrysalis2.com")?
.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 = Seed::from_bytes(&hex::decode(env::var("NONSECURE_USE_OF_DEVELOPMENT_SEED_1").unwrap())?);
// Here all funds will be send to the address with the lowest index in the range
let address = consolidate_funds(&iota, &seed, 0, address_range).await?;
println!("Funds consolidated to {}", address);
Ok(())
}