diff --git a/README.md b/README.md index 472222ad6..3a9db3998 100644 --- a/README.md +++ b/README.md @@ -88,3 +88,21 @@ Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. + +## Esplora backend example + +BDK can be used with an Esplora backend to fetch blockchain data without running a full node. + +Below is a minimal example showing how to query the current blockchain height using `bdk_esplora`: + +```rust +use bdk_esplora::EsploraClient; + +fn main() -> Result<(), Box> { + let esplora = EsploraClient::new("https://blockstream.info/api")?; + let height = esplora.get_height()?; + println!("Current block height: {}", height); + Ok(()) +} +``` + diff --git a/examples/example_esplora/src/main.rs b/examples/example_esplora/src/main.rs index 99f72391c..043f76a72 100644 --- a/examples/example_esplora/src/main.rs +++ b/examples/example_esplora/src/main.rs @@ -69,6 +69,7 @@ pub struct EsploraArgs { esplora_url: Option, } +use std::time::Duration; impl EsploraArgs { pub fn client(&self, network: Network) -> anyhow::Result { let esplora_url = self.esplora_url.as_deref().unwrap_or(match network { @@ -79,11 +80,15 @@ impl EsploraArgs { _ => panic!("unsupported network"), }); - let client = esplora_client::Builder::new(esplora_url).build_blocking(); + let client = esplora_client::Builder::new(esplora_url) + .timeout(60) + .build_blocking(); + Ok(client) } } + #[derive(Parser, Debug, Clone, PartialEq)] pub struct ScanOptions { /// Max number of concurrent esplora server requests. @@ -286,4 +291,4 @@ fn main() -> anyhow::Result<()> { ..Default::default() })?; Ok(()) -} +} \ No newline at end of file