A minimal Bitcoin Core RPC client designed specifically for the Bitcoin Dev Kit (BDK). It retrieves blockchain data from bitcoind over JSON-RPC and supports multiple versions of Bitcoin Core (v28.0 through v30.0+).
- Version Pinning: Explicit support for different Bitcoin Core RPC schemas via feature flags (28_0, 29_0, 30_0).
- Minimal Dependencies: Uses bitreq_http for a lightweight HTTP transport by default.
- Wallet-Agnostic: Focused on blockchain data emission (blocks, headers, mempool) rather than wallet management.
- Robust Error Handling: Specific error variants for RPC failures, deserialization issues, and transport timeouts.
Add this to your Cargo.toml:
# For the latest Bitcoin Core (v30.0+)
bdk-bitcoind-client = { version = "0.1.0" }
# OR for older nodes (e.g., v28.x)
bdk-bitcoind-client = { version = "0.1.0", default-features = false, features = ["28_0"] }use bdk_bitcoind_client::{Auth, Client};
use std::path::PathBuf;
fn main() -> anyhow::Result<()> {
// 1. Setup authentication (Cookie file is recommended for security)
let auth = Auth::CookieFile(PathBuf::from("/path/to/regtest/.cookie"));
// 2. Initialize the client
let client = Client::with_auth("http://127.0.0.1:18443", auth)?;
// 3. Query the blockchain
let block_count = client.get_block_count()?;
let best_hash = client.get_block_hash(block_count)?;
// 4. Get verbose headers (handles schema differences automatically)
let header = client.get_block_header_verbose(&best_hash)?;
println!("Chain tip: {} at height {}", header.hash, header.height);
Ok(())
}Bitcoin Core often changes its JSON-RPC response fields (e.g., adding the target field in v29/v30). This client manages these differences through compile-time features.
| Feature | Bitcoin Core Version | Notes |
|---|---|---|
| 30_0 (default) | v30.x and newer | Supports latest target and difficulty fields. |
| 29_0 | v29.x | Aligned with v29 schema. |
| 28_0 | v28.x and older | Omits newer fields |
To run tests against a specific Bitcoin Core version, use the corresponding feature flag:
cargo test --no-default-features --features 28_0
The library maintain a MSRV of 1.85.0.
This project has a justfile for easy command running. You must have just installed.
To see a list of available recipes: just
Licensed under either of
- Apache License, Version 2.0 (Apache 2.0 or https://www.apache.org/licenses/LICENSE-2.0)
- MIT License (MIT or https://opensource.org/licenses/MIT)
at your option.
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.