Crate blockbook

source ·
Expand description

Rust Blockbook Library

This crate provides REST and WebSocket clients to query various information from a Blockbook server, which is a block explorer backend created and maintained by SatoshiLabs.

Note that this crate currently only exposes a Bitcoin-specific API, even though Blockbook provides a unified API that supports multiple cryptocurrencies.

The methods exposed in this crate make extensive use of types from the bitcoin crate to provide strongly typed APIs.

An example of how to use the REST client:

let client = blockbook::Client::new(url).await?;

// query the Genesis block hash
let genesis_hash = client
    .block_hash(&blockbook::Height::from_consensus(0).unwrap())
    .await?;
assert_eq!(
    genesis_hash.to_string(),
    "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
);

// query the full block
let genesis = client.block_by_hash(&genesis_hash).await?;
assert_eq!(genesis.previous_block_hash, None);

// inspect the first coinbase transaction
let tx = genesis.txs.get(0).unwrap();
assert!((tx.vout.get(0).unwrap().value.to_btc() - 50.0).abs() < f64::EPSILON);

For an example of how to use the WebSocket client, see its documentation.

Available feature flags

  • bdk - adds functions for integration with the bdk wallet library

Supported Blockbook Version

The currently supported version of Blockbook is commit 95ee9b5b.

Re-exports

  • pub use bitcoin::hashes;

Modules

  • The WebSocket client. This module contains the WebSocket Client for interacting with a Blockbook server via a WebSocket connection. The client provides numerous query-response methods, as well as a few subscription methods.

Structs

Enums