indexer-external-calls

Implements external RPC and fetch calls in indexer handlers using the Effect API.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires envio, viem.

What problem does it solve?

HyperIndex handlers run twice — a parallel preload pass and a sequential pass — so any direct fetch or RPC call inside a handler double-executes and blocks parallelization. This Skill shows how to route all external I/O through the Effect API so calls are deduplicated, cached, and rate-limited correctly.

Core Features & Use Cases

  • Effect Definition with createEffect: Wrap external calls in typed effects with S schema validation for input and output, plus cache and rateLimit options.
  • RPC Batching with viem: Configure transports with batch: true so the preload pass collapses concurrent reads into a few JSON-RPC requests.
  • Cross-Chain Caching Control: Use the crossChain option to choose between one shared global cache or per-chain caches with access to context.chain.id.
  • Use Case: When indexing a Transfer event, call context.effect(getTokenMetadata, address) to fetch ERC-20 name, symbol, and decimals once per token instead of once per event.

Quick Start

Ask the AI to refactor a handler that fetches token metadata via RPC into a createEffect definition called through context.effect with caching enabled.

Frequently Asked Questions about indexer-external-calls

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

FAQPage Schema
How do I make RPC calls from a HyperIndex event handler?

Wrap the RPC call in createEffect with a name, S schema input and output, then invoke it via context.effect inside the handler. This prevents double execution during the preload pass and enables caching and batching.

Why do my fetch requests execute twice in Envio handlers?

Handlers run twice: a parallel preload pass that warms caches and a sequential pass that applies state changes. Any fetch or RPC call made directly in the handler body double-executes, so all external I/O must go through context.effect.

How do I batch viem RPC requests in an indexer?

Pass { batch: true } to the viem http transport when creating the public client. The preload pass fires effects concurrently for the whole batch, and batching collapses them into a few JSON-RPC requests instead of one per read.

What does the crossChain option do in createEffect?

crossChain controls whether an effect input is cached and rate-limited once globally or once per chain. Set it to false for chain-dependent results like on-chain reads, which also makes context.chain.id available in the effect body.

What schema types does the S validation library support?

S supports string, number, bigint, boolean, object schemas via S.schema, arrays, unions with null, and optional fields. These schemas validate effect inputs and outputs and drive deduplication keyed by input hash.