A Rust client library for StreamingFast's Firehose protocol, providing gRPC bindings for streaming and fetching blockchain data.
- gRPC client bindings for Firehose v2 API
- Streaming support via
StreamClientfor continuous block sequences - Fetch support via
FetchClientfor individual block retrieval - Serde integration for JSON serialization of all message types
- Flexible block requests by number, hash, or cursor
Add to your Cargo.toml:
[dependencies]
firehose-rs = "0.3"Protoc compiler must be installed - the build script compiles protocol buffer definitions to generate gRPC code. Install via:
# macOS
brew install protobuf
# Ubuntu/Debian
apt install protobuf-compiler
# Or download from https://github.com/protocolbuffers/protobuf/releasesuse firehose_rs::{StreamClient, Request};
use tonic::transport::Channel;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to a Firehose endpoint
let channel = Channel::from_static("https://your-firehose-endpoint:443")
.connect()
.await?;
let mut client = StreamClient::new(channel);
// Create a streaming request starting from block 1000
let request = Request {
start_block_num: 1000,
stop_block_num: 2000,
final_blocks_only: true,
..Default::default()
};
// Stream blocks
let mut stream = client.blocks(request).await?.into_inner();
while let Some(response) = stream.message().await? {
println!("Received block at cursor: {}", response.cursor);
}
Ok(())
}use firehose_rs::{FetchClient, SingleBlockRequest};
use tonic::transport::Channel;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let channel = Channel::from_static("https://your-firehose-endpoint:443")
.connect()
.await?;
let mut client = FetchClient::new(channel);
// Fetch block by number
let request = SingleBlockRequest::new_by_block_number(12345);
let response = client.block(request).await?;
println!("Fetched block: {:?}", response.into_inner().block);
Ok(())
}use firehose_rs::SingleBlockRequest;
// Fetch a specific block by its hash and number
let request = SingleBlockRequest::new_by_block_hash_and_number(
"0xabc123...".to_string(),
12345,
);| Client | Description |
|---|---|
StreamClient |
Streaming RPC for continuous block sequences |
FetchClient |
Unary RPC for individual block retrieval |
| Type | Description |
|---|---|
Request |
Streaming request with start/stop block configuration |
SingleBlockRequest |
Single block request by number, hash, or cursor |
| Type | Description |
|---|---|
Response |
Streaming response with block data and cursor |
SingleBlockResponse |
Single block fetch response |
| Trait | Description |
|---|---|
HasNumberOrSlot |
Unified access to block number or slot |
FromResponse |
Convert protobuf responses to domain types |
This library implements the Firehose v2 protocol by StreamingFast.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Run tests
cargo test --all-features
# Run lints
cargo clippy --all-targets --all-features -- -D warnings
# Check formatting
cargo fmt --all -- --checkThis project is licensed under the Apache License 2.0 - see the LICENSE file for details.
The protocol buffer definitions in protos/ are from StreamingFast and are also licensed under Apache 2.0.
- StreamingFast for creating the Firehose protocol
- Tonic for the excellent gRPC framework
- Prost for protocol buffer support