indexer-handlers

Write and edit Envio HyperIndex event handlers using the context entity API.

546|55|Updated May 24, 2024
One-click install
npx skills add https://github.com/enviodev/hyperindex --skill indexer-handlers
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: indexer-handlers
Source: https://github.com/enviodev/hyperindex/tree/main/packages/cli/templates/static/shared/.claude/skills/indexer-handlers
Command: npx skills add https://github.com/enviodev/hyperindex --skill indexer-handlers

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing blockchain event handlers for HyperIndex requires knowing the exact handler registration signature, the context entity CRUD API, and framework-specific pitfalls like read-only entities and _id relationship fields. This Skill provides that reference so handlers compile and behave correctly on the first pass.

Core Features & Use Cases

  • Handler Registration: Documents indexer.onEvent with contract, event, wildcard, where, and fields options, including typed block and transaction field selection.
  • Context Entity API: Covers get, getOrThrow, getOrCreate, getWhere operators (_eq, _gt, _lt, _gte, _lte, _in), and sync set/deleteUnsafe writes.
  • Pitfall Guidance: Explains entity ID uniqueness across chains, spread-based updates on read-only entities, _id suffix relationships, and decimal normalization.
  • Use Case: When adding a Transfer event handler for an ERC-20 contract, follow the registration pattern, query existing entities with getWhere, and update them with spread syntax, then run pnpm codegen and pnpm tsc --noEmit to verify.

Quick Start

Write a HyperIndex event handler for my contract's Transfer event that updates a balance entity using the context API.

Frequently Asked Questions about indexer-handlers

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write an event handler in Envio HyperIndex?

Register a handler with indexer.onEvent, passing an options object with contract and event names plus an async handler receiving event and context. Access decoded parameters via event.params and persist entities with context.Entity.set.

How do I query entities by field values in HyperIndex handlers?

Use context.Entity.getWhere with operators like _eq, _gt, _lt, _gte, _lte, and _in on any non-derived field. Multiple fields combine with AND semantics, and marking fields @index in the schema avoids indexing pauses.

Why does updating an entity from context.Entity.get fail?

Entities returned by context.Entity.get are read-only, so mutating them directly fails. Spread the entity into a new object with the changed fields and pass it to context.Entity.set instead.

How do entity relationships work between schema and handlers?

The schema declares the entity reference like token0: Token!, while handlers use the _id-suffixed field token0_id typed as the referenced entity's id. Never use the bare name in handlers or the _id suffix in the schema.

How do I keep entity IDs unique across multiple chains?

With disable_default_cross_chain enabled, IDs only need uniqueness within a chain since rows are keyed by id and chainId. Otherwise, prefix IDs with event.chainId to prevent collisions between chains.