Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 8da288a

Browse files
committed
Add utxo example
1 parent ad7345c commit 8da288a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

bee-inx/examples/utxo.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2022 IOTA Stiftung
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use bee_inx::{client::Inx, Error, MilestoneRangeRequest};
5+
use futures::StreamExt;
6+
7+
#[tokio::main]
8+
async fn main() -> Result<(), Error> {
9+
dotenvy::dotenv().ok();
10+
let inx_connect_url = std::env::var("INX_CONNECT_URL").unwrap_or_else(|_| "http://localhost:9029".to_string());
11+
12+
let mut inx = Inx::connect(&inx_connect_url).await?;
13+
println!("Connected via INX to node at {inx_connect_url}");
14+
15+
let mut unspent_outputs = inx.read_unspent_outputs().await?;
16+
17+
let mut count = 0;
18+
while let Some(_) = unspent_outputs.next().await {
19+
count += 1;
20+
}
21+
println!("Read {count} unspent outputs.");
22+
23+
let mut ledger_update_feed = inx.listen_to_ledger_updates(MilestoneRangeRequest::from(..)).await?;
24+
25+
while let Some(ledger_update) = ledger_update_feed.next().await {
26+
let ledger_update = ledger_update?;
27+
println!("{:?}", ledger_update);
28+
}
29+
30+
Ok(())
31+
}

0 commit comments

Comments
 (0)