This is an unofficial fork of enviodev/hypersync-client-go.
We maintain this fork for our own internal use at terminally-online. It includes additional features and modifications that may diverge from the upstream implementation.
For production use, we recommend the official client: github.com/enviodev/hypersync-client-go
This fork includes the following features not present in the upstream:
Collect()- Fetch all data for a query into a singleQueryResponse(handles pagination automatically)CollectArrow()- Fetch all data as raw Arrow batches for maximum performanceCollectParquet()- Stream data directly to Parquet files for local storage
GetEvents()- Query with automatic joining of blocks, transactions, and logs into unifiedEventobjectsStreamEvents()- Stream events with automatic joiningCollectEvents()- Collect all events with automatic joining
CallDecoder- Decode transaction calldata and trace output dataNewCallDecoderFromSignatures()- Create decoder from function signatures like"transfer(address,uint256)"NewCallDecoderFromABI()- Create decoder from JSON ABIDecodeInput()- Decode transaction input dataDecodeOutput()- Decode return values from traces
- Dynamic batch size adjustment - Automatically adjusts batch size based on response size (matching Rust canonical implementation)
StreamHeight()- SSE-based real-time block height streaming with auto-reconnectGetChainId()- Retrieve chain ID from HyperSync server- Bearer token auth for RPC - Both HyperSync API and HyperRPC support bearer token authentication
- Environment-based configuration - Examples use
.envfiles for bearer tokens
go get github.com/terminally-online/hypersync-client-gopackage main
import (
"context"
"math/big"
"os"
hypersyncgo "github.com/terminally-online/hypersync-client-go"
"github.com/terminally-online/hypersync-client-go/options"
"github.com/terminally-online/hypersync-client-go/utils"
"github.com/joho/godotenv"
)
func main() {
_ = godotenv.Load()
bearerToken := os.Getenv("HYPERSYNC_BEARER_TOKEN")
opts := options.Options{
Blockchains: []options.Node{{
Type: utils.EthereumNetwork,
NetworkId: utils.EthereumNetworkID,
Endpoint: "https://eth.hypersync.xyz",
RpcEndpoint: "https://eth.rpc.hypersync.xyz",
BearerToken: &bearerToken,
}},
}
ctx := context.Background()
hsClient, _ := hypersyncgo.NewHyper(ctx, opts)
client, _ := hsClient.GetClient(utils.EthereumNetworkID)
// Get current height
height, _ := client.GetHeight(ctx)
// Stream blocks
stream, _ := client.StreamBlocksInRange(ctx, big.NewInt(20000000), height, nil)
for response := range stream.Channel() {
// Process blocks...
stream.Ack()
}
}See the examples directory:
blocks_in_range.go- Stream blockslogs_in_range.go- Stream event logstransactions_in_range.go- Stream transactionstraces_in_range.go- Stream tracesparquet_collect.go- Export data to Parquet filesstream_height.go- Real-time height streaming via SSEsighash.go- Query by function signatureerc721_events_decoded.go- Decode ERC721 events
Create a .env file (see .env.example):
HYPERSYNC_BEARER_TOKEN=your-api-token-hereGet your API token from envio.dev/app/api-tokens
This fork maintains the same license as the upstream repository.
This fork is maintained by terminally-online. For issues specific to this fork, please open an issue in this repository. For general HyperSync issues, please use the official repository.