forked from iotaledger/iota.rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_funds.rs
57 lines (52 loc) · 1.47 KB
/
get_funds.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
//! cargo run --example get_funds --release
use iota_client::{Client, Seed};
use serde::Deserialize;
use std::time::Duration;
use tokio::time::sleep;
extern crate dotenv;
use dotenv::dotenv;
use std::env;
#[derive(Debug, Deserialize)]
struct FaucetMessageResponse {
id: String,
}
#[derive(Debug, Deserialize)]
struct FaucetResponse {
data: FaucetMessageResponse,
}
#[tokio::main]
async fn main() {
// Create a client instance
let iota = Client::builder()
.with_node("https://api.hornet-0.testnet.chrysalis2.com") // Insert the node here
.unwrap()
.finish()
.await
.unwrap();
// This example uses dotenv, which is not safe for use in production
dotenv().ok();
let seed = Seed::from_bytes(&hex::decode(env::var("NONSECURE_USE_OF_DEVELOPMENT_SEED_1").unwrap()).unwrap());
let addresses = iota
.get_addresses(&seed)
.with_account_index(0)
.with_range(0..1)
.finish()
.await
.unwrap();
println!("{}", addresses[0]);
for i in 0..1 {
let response: FaucetResponse = ureq::get(&format!(
"https://faucet.testnet.chrysalis2.com/api?address={}",
addresses[0]
))
.call()
.unwrap()
.into_json()
.unwrap();
println!("{}: {:?}", i, response);
// Faucet spam protection time
sleep(Duration::from_secs(60)).await;
}
}