use std::str::FromStr; use bdk_wallet::bitcoin::{Address, Amount, Network}; use crate::bitcoin::clients; /// Demonstrates the use of bdk with the Esplora client. /// /// This is more complex than the bare `bdk` crate, but the esplora client works. /// /// Also, it very handily works with the mutinynet.com esplora server, which is configured /// with 30 second block times. pub(crate) async fn run() -> Result<(), anyhow::Error> { let mut dave = clients::esplora::create_wallet("dave", Network::Signet)?; let _next_address = dave.next_unused_address()?; let balance = dave.balance(); println!("Wallet balance before syncing: {} sats", balance.total()); dave.sync().await?; let balance = dave.balance(); println!("Wallet balance after syncing: {} sats", balance.total()); let faucet_address = Address::from_str("mkHS9ne12qx9pS9VojpwU5xtRd4T7X7ZUt")? .require_network(Network::Signet)?; let send_amount = Amount::from_sat(5000); if balance.total() < send_amount { println!( "Please send at least {} sats to the receiving address", send_amount ); std::process::exit(0); } let tx = dave.build_send_tx(faucet_address, send_amount)?; dave.broadcast(&tx).await?; println!("Tx broadcasted! Txid: {}", tx.compute_txid()); Ok(()) }