HyperSync Client
A high-performance Rust client for the HyperSync protocol, enabling efficient retrieval of blockchain data including blocks, transactions, logs, and traces.
Features
- High-performance streaming: Parallel data fetching with automatic retries
- Flexible querying: Rich query builder API for precise data selection
- Multiple data formats: Support for Arrow, Parquet, and simple Rust types
- Event decoding: Automatic ABI decoding for smart contract events
- Real-time updates: Live height streaming via Server-Sent Events
- Production ready: Built-in rate limiting, retries, and error handling
Quick Start
use hypersync_client::{Client, net_types::{Query, LogFilter, LogField}, StreamConfig};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create a client for Ethereum mainnet
let client = Client::builder()
.chain_id(1)
.api_token(std::env::var("ENVIO_API_TOKEN")?)
.build()?;
// Query ERC20 transfer events from USDC contract
let query = Query::new()
.from_block(19000000)
.to_block_excl(19001000)
.where_logs(
LogFilter::all()
.and_address(["0xA0b86a33E6411b87Fd9D3DF822C8698FC06BBe4c"])?
.and_topic0(["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"])?
)
.select_log_fields([LogField::Address, LogField::Topic1, LogField::Topic2, LogField::Data]);
// Get all data in one response
let response = client.get(&query).await?;
println!("Retrieved {} blocks", response.data.blocks.len());
// Or stream data for large ranges
let mut receiver = client.stream(query, StreamConfig::default()).await?;
while let Some(response) = receiver.recv().await {
let response = response?;
println!("Streaming: got blocks up to {}", response.next_block);
}
Ok(())
}
Main Types
- [
Client] - Main client for interacting with HyperSync servers - [
net_types::Query] - Query builder for specifying what data to fetch - [
StreamConfig] - Configuration for streaming operations - [
QueryResponse] - Response containing blocks, transactions, logs, and traces - [
ArrowResponse] - Response in Apache Arrow format for high-performance processing
Authentication
You'll need a HyperSync API token to access the service. Get one from https://envio.dev/app/api-tokens.
Examples
See the examples/ directory for more detailed usage patterns including:
- ERC20 token transfers
- Wallet transaction history
- Event decoding and filtering
- Real-time data streaming