HyperIndex Documentation
repository·main·Indexed 19 days ago
https://github.com/enviodev/hyperindexA high-performance multichain blockchain indexing framework that transforms onchain events into queryable GraphQL databases. Powered by the HyperSync engine, it supports EVM, SVM (experimental), and Fuel blockchains, offering significantly faster sync speeds than traditional RPC-based indexers. The framework includes a CLI for project scaffolding, a code generator for schema and configuration, and an Effect API for external calls within handlers.
What's inside HyperIndex
- HyperIndex is a full-featured blockchain indexing framework that transforms onchain events into structured, queryable databases with GraphQL APIs. It is powered by HyperSync, a proprietary Rust-based data engine that enables up to 2000x faster data access compared to traditional RPC endpoints by retrieving multiple blocks per round trip. This makes historical backfills significantly faster (e.g., syncing in minutes instead of days).
How HyperSync works
mainHyperSync is the underlying data engine for HyperIndex and is enabled by default for all supported networks. Unlike standard RPC calls that fetch data block-by-block, HyperSync retrieves multiple data points per round trip with advanced filtering.
Key benefits:
- Up to 2000x faster sync speeds.
- Lower infrastructure costs.
- No rate limit issues on supported networks.
HyperSync can also be used independently of HyperIndex as a custom data pipeline in Python, Rust, Node.js, and Go.
Understand the HyperIndex License and Usage Rights
mainHyperIndex is provided under an End-User License Agreement (EULA) that distinguishes between the Software (the HyperIndex tool itself) and Generated Code (the code produced by the tool based on your input).
Software Usage (HyperIndex)
- Single Instance: You are granted a non-exclusive, royalty-free, worldwide, non-sublicensable, and non-transferable license to install and operate one instance of the Software on a single device (physical or virtual) for one individual at a time.
- Prohibited Actions: You may not publish, copy (except for backups), rent, lease, or lend the Software. You are also prohibited from using the Software as server software for commercial hosting or making it available for simultaneous use by multiple users over a network.
- Restrictions: Reverse engineering, decompiling, or disassembling the Software is prohibited except where permitted by law or specific open-source component licenses.
Generated Code Usage
Unlike the Software, you have broader rights regarding the Generated Code:
- Permitted Actions: You can freely use, copy, distribute, make available, and create derivative works of the Generated Code.
- Prohibited Actions: You may not offer the Generated Code (or software containing it) to third parties as a hosted or managed service that grants access to a significant portion of the Software's features.
- Attribution: If you use the Generated Code to develop and release a new software, product, or service, you must include proper credit to HyperIndex in your license agreement.
Core indexing patterns in HyperIndex
mainThis template demonstrates three fundamental patterns for building Solana indexers with HyperIndex:
- Configuration: Declaring a Solana program and its instructions in
config.yamlusingecosystem: svmand theexperimental.programs[].instructions[]schema. - Instruction Handling: Using
indexer.onInstruction({program, instruction}, handler)to intercept and process positional accounts and raw instruction data. - State Persistence: Persisting per-instruction state to typed entities (e.g.,
TokenMetadataAccount) and maintaining counters (e.g.,ProgramStats).
- Configuration: Declaring a Solana program and its instructions in
Use legacy Anchor IDL format for HyperIndex
mainHyperIndex supports legacy Anchor format (pre-0.30) IDLs. These IDLs contain top-level keys like
name,version,instructions,accounts,types,events, anderrors.Key characteristics of legacy IDLs:
- They do not contain a top-level
addressfield. - They do not contain
metadata.specor per-instructiondiscriminatorbyte arrays. - HyperIndex computes the 8-byte discriminator itself using
sha256("global:<snake_case_name>")[..8]during decoding. - Because legacy IDLs omit the
program_id, you must provide theprogram_idmanually in yourconfig.yamlto pair it with the IDL.
- They do not contain a top-level
Core files in a HyperIndex project
mainA HyperIndex project is defined by three primary files:
config.yaml: Defines networks, contracts, events, and specific indexing behavior.schema.graphql: Defines the shape of your indexed data (the GraphQL schema).src/handlers: Contains your custom logic for processing events, written in TypeScript, JavaScript, or ReScript.
Understand Envio's licensing model and vendor lock-in
mainEnvio uses a licensing model that provides open-source-like benefits but is not OSI-recognized. The model is designed to allow developers to avoid vendor lock-in while protecting Envio's hosted services and HyperSync business model.
To avoid dependency on Envio's hosted services, developers can:
- Self-host: The licenses permit self-hosting of the indexers.
- Specify an RPC URL: By specifying an RPC URL in the indexer configuration, you bypass HyperSync and run the indexer independently.
Note that while the generated code is open and public, the code generator itself is under a commercial license.
Index contracts deployed from factory contracts with HyperIndex
mainHyperIndex allows you to index contracts that are deployed dynamically by a factory contract (e.g., Uniswap V3 Pools) without needing to pre-define their addresses.
To implement this, use the
indexer.contractRegisterhandler. This handler listens for the specific event emitted by the factory contract that contains the new contract's address. Inside the handler, you use thecontext.chain.<contract-name>.add(<address>)method to register the new instance with the indexer.indexer.contractRegister( { contract: "UniswapV3Factory", event: "PoolCreated" }, async ({ event, context }) => { context.chain.UniswapV3Pool.add(event.params.pool); }, );How the Effect API works in HyperIndex
mainThe Effect API allows you to perform external calls (such as RPC calls or API requests) directly from within your indexer handlers. These calls execute in the handler context and support built-in features like caching and rate limiting to optimize performance and prevent hitting external API limits.
To use an effect, you first define it using
createEffectand then invoke it within a handler usingcontext.effect(EFFECT_NAME, INPUT_DATA).indexer.onEvent({ contract: "CONTRACT", event: "EVENT" }, async ({ event, context }) => { const effectOutput = await context.effect(YOUR_EFFECT, EFFECT_INPUTS); });Pre-requisites for the Envio ERC20 Template
mainBefore running the template, ensure your environment meets the following requirements:
- Node.js: v22+ (v24 is recommended)
- pnpm: v8 or newer
- Container Runtime: Docker or Podman
Run the svm_test scenario
mainTo execute the minimal SVM scenario, which demonstrates the
indexer.onSlotAPI and the SVM-specific filter decoder located inpackages/envio/src/Main.res, follow these steps in your terminal:- Install dependencies using
pnpm. - Generate the necessary code using the
envio codegencommand. - Execute the tests.
Note: This scenario is designed to test SVM-specific logic within the Envio framework.
pnpm install pnpm exec envio codegen pnpm test- Install dependencies using
Scaffold a new HyperIndex project
mainTo start a new indexing project, use the
envio initcommand. This scaffolds the entire project structure, including configuration, schema, and handler functions. You can generate an indexer from a specific contract address, use pre-defined templates, or start from an existing example.Requirements:
- Node.js
- Docker (required only for local development)
Command:
pnpx envio init