Type-safe Rust client for Bitcoin Core v29 RPCs, with test node support. Generated from a version-flexible toolchain.
Compared to hand-written RPC clients, this toolchain offers:
- Reduced repetition
- Fewer versioning issues
- Increased compile-time checks
- Support for all Bitcoin p2p networks (mainnet, regtest, signet, testnet, and testnet4)
- Improved isolation from environment and port conflicts
The crate is organized into focused modules:
client_trait/
: Trait definitions for type-safe RPC method callsnode/
: Multi-network node management and test client supporttest_node/
: Integration testing helpers with embedded Bitcoin nodestransport/
: Async RPC transport with error handling and batchingtypes/
: Generated type definitions for all RPC responses
This asynchronous example uses Tokio and enables some
optional features, so your Cargo.toml
could look like this:
[dependencies]
bitcoin-rpc-midas = "0.1.6"
tokio = { version = "1.0", features = ["full"] }
And then the code:
use bitcoin_rpc_midas::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = BitcoinTestClient::new_with_network(Network::Regtest).await?;
let blockchain_info = client.getblockchaininfo().await?;
println!("Blockchain info:\n{:#?}", blockchain_info);
Ok(())
}
Requires a working bitcoind
executable.
This crate is generated by bitcoin-rpc-codegen, which systematically derives type-safe clients from Bitcoin Core's RPC specification. The generator ensures consistency, reduces duplication, and maintains alignment with upstream changes.
Contributors are warmly welcome, see CONTRIBUTING.md.
Bitcoin RPC Code Generator is released under the terms of the MIT license. See LICENSE for more information or see https://opensource.org/license/MIT.
This library communicates directly with bitcoind
.
For mainnet use, audit the code carefully, restrict RPC access to trusted hosts, and avoid exposing RPC endpoints to untrusted networks.