Expand description
§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 serversnet_types::Query- Query builder for specifying what data to fetchStreamConfig- Configuration for streaming operationsQueryResponse- Response containing blocks, transactions, logs, and tracesArrowResponse- 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
Re-exports§
pub use hypersync_format as format;pub use hypersync_net_types as net_types;pub use hypersync_schema as schema;
Modules§
- arrow_
reader - Reader types for reading Arrow record batch data as native Rust types.
- preset_
query - Preset queries for common use cases.
- simple_
types - Base object types for the Hypersync client.
Structs§
- Arrow
Response Data - Query response in Arrow format
- Call
Decoder - Decode input data parsing input data.
- Client
- Client to handle http requests and retries.
- Client
Builder - Builder for creating a hypersync client with configuration options.
- Client
Config - Configuration for the hypersync client.
- Column
Mapping - Column mapping for stream function output. It lets you map columns you want into the DataTypes you want.
- Decoder
- Decode logs parsing topics and log data.
- Query
Response - Query response from hypersync instance. Contain next_block field in case query didn’t process all the block range
- Stream
Config - Config for hypersync event streaming.
Enums§
- Data
Type DataTypeis an enumeration representing the different data types that can be used in the column mapping. Each variant corresponds to a specific data type.- Height
Stream Event - Events emitted by the height stream.
- HexOutput
- Determines format of Binary column
- Serialization
Format - Determines query serialization format for HTTP requests.
Type Aliases§
- Arrow
Response - Alias for Arrow Query response