For AI agents: the documentation index is at /llms.txt. Markdown versions of pages are available by appending .md to the URL.
Skip to main content

Quickstart with AI

Build an Envio HyperIndex indexer end-to-end with an AI coding assistant.

Most developers now reach for an AI coding assistant before they open a file. This guide walks through an AI-centric flow for creating, developing, and deploying a HyperIndex indexer. It is semi-generic, so any capable AI coding assistant (Cursor, Codex, Windsurf, Copilot Agent, Continue, etc.) will work. That said, we've seen the best results with Claude Code and recommend starting there.

Prefer the interactive flow?

If you'd rather drive the CLI yourself, see the Quickstart.


Prerequisites​


Step 1. Initialize The Indexer​

Open Claude Code, Codex or Cursor and give it the command plus what you want to index, for example:

Run `pnpx envio init` and build an indexer that tracks WETH deposits and withdrawals on Ethereum.

If you leave out the goal, the agent asks you for it.

Built for AI Agents​

When envio init runs under an agent without a subcommand, it doesn't open the interactive prompts. It prints a plan for the agent to stderr and exits with code 2. Code 2 means "the agent has a follow-up step", not a failure. The plan tells the agent to ask you for an API token if ENVIO_API_TOKEN isn't set, work out the chain and contract from your goal, and then run envio init again with flags.

envio init treats the session as an agent when CLAUDECODE or CI is set, when TERM is dumb, or when stdout is not a terminal. Set ENVIO_TUI to override this: true or 1 forces the interactive prompts, false or 0 forces agent mode.

In agent mode, every answer comes from flags. Always pass the directory (-d) and --single-contract --all-events, so nothing waits for input. To import a verified contract from a block explorer:

pnpx envio init contract-import explorer \
-n my-indexer \
-c 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 \
-b ethereum-mainnet \
--single-contract --all-events \
-d my-indexer

Here -b takes a network name, such as ethereum-mainnet or base, not a chain ID, even though the printed plan shows -b ${chainId}. Run pnpx envio init contract-import explorer --help for the list of names. The explorer import fetches the verified ABI through Envio's API at envio.dev, so that host must be reachable. It names the contract after its verified name on the explorer, and explorer has no --contract-name flag.

If the explorer import fails. When the lookup fails, for example with Failed to fetch contract import or Failed to find the verified contract on a block explorer, envio init prints Use the Local ABI import option instead. and falls back to asking for an ABI file path. In agent mode that prompt exits with code 1 and The input device is not a TTY. Don't retry explorer. Import from an ABI file with local instead:

  1. Save the contract's ABI as a JSON file. Either a bare ABI array or a Hardhat or Foundry build artifact with an abi key works. Copy the verified ABI from the contract's page on the chain's block explorer, or take it from the contract's build output. For a proxy, use the implementation's ABI.

    Without browser access, the agent has two other ways to get an ABI. An events-only ABI is enough, so the agent can write a bare array with just the events to index from their signatures, for example [{"type":"event","name":"Transfer","anonymous":false,"inputs":[{"name":"from","type":"address","indexed":true},{"name":"to","type":"address","indexed":true},{"name":"value","type":"uint256","indexed":false}]}]. If the sandbox can reach it, Sourcify's API also returns verified ABIs: curl "https://sourcify.dev/server/v2/contract/<CHAIN_ID>/<ADDRESS>?fields=abi", then save the abi field.

  2. Run local with the contract's own address in -c (the proxy address for a proxy). Here -b takes a name or a chain ID:

pnpx envio init contract-import -c <ADDRESS> local \
-a ./abis/MyContract.json --contract-name MyContract \
-b 8453 \
--single-contract --all-events \
-d my-indexer

You can also use local from the start when you already have the ABI. To skip the ABI, list events by signature under the contract's events: in config.yaml, such as - event: Transfer(address indexed from, address indexed to, uint256 value), then run pnpm envio codegen. For a chain HyperSync doesn't support, add -r <RPC_URL> -s <START_BLOCK> to the local command. Other flags: -l typescript|rescript (default typescript) and --package-manager pnpm|npm|yarn|bun (default pnpm when it's installed, otherwise npm). Run pnpx envio init --help, or see the Envio CLI reference, for every option.

With no single contract to import, for example a wildcard indexer over every ERC-20, start from a template instead. The erc20 template is already set up for two chains, with tests:

pnpx envio init template -t erc20 -n my-indexer -d my-indexer

envio init then writes the project, runs codegen, installs dependencies and initializes a git repository. It ends by suggesting pnpm test as the first command for an agent.

No flag picks a subset of events, so to index only some of them, import with --all-events and then trim the project:

  1. Delete the unwanted - event: lines from config.yaml.
  2. Delete their indexer.onEvent(...) registrations and type imports from src/handlers/<Contract>.ts.
  3. Delete or rewrite the tests in src/indexer.test.ts that use them. The generated test covers the first event in the ABI.
  4. Optionally, delete their entity types from schema.graphql.
  5. Run pnpm codegen, then pnpm tsc --noEmit and pnpm test.

To read these docs from the terminal, an agent can run envio tools search-docs "<query>" and envio tools fetch-docs <url> (Envio 3.1 and newer). They print plain text and need no setup or token.

Skills For Your Agent​

envio init adds 17 skills to the new project's .claude/skills/ folder, one SKILL.md per topic: config, schema, handlers, testing, factory contracts, wildcard indexing, event filters, block handlers, multichain, external calls, transactions, traces, performance, troubleshooting, running several indexers locally, the envio-cloud CLI and searching the docs. Claude Code loads them automatically.

envio init doesn't create an AGENTS.md, an .agents/ folder or Cursor rules. If your agent doesn't load skills from .claude/skills/, tell it to read them first, for example: "Read every SKILL.md under .claude/skills/ before you change the indexer."

After you upgrade envio, refresh the skills from the project root (Envio 3.0 and newer):

pnpm envio skills update

It rewrites every skill whose SKILL.md has metadata.managed-by: envio, deletes the skills that older versions shipped under other names, and leaves your own skills alone.

About Envio API Token​

The Envio API token is your HyperSync API token. A few things to know:

  • The token can't currently be created programmatically. You generate one by logging in to envio.dev/app/api-tokens and copying it into ENVIO_API_TOKEN in your indexer's .env. An agent can't do this step for you.
  • It's only required for local development and self-hosted deployments. Indexers running on Envio Cloud get special access and don't need a custom token.
  • It's required when using Envio as the data provider (HyperSync). If you only use an external RPC as the data source, no token is needed.
  • envio init reads the token from --api-token or the ENVIO_API_TOKEN environment variable and writes it to the new project's .env. --api-token always sets this Envio token, wherever it appears on the command line. That includes after explorer, whose --help describes it as a block explorer key. Explorer import needs no block explorer key. In agent mode it stops with an error when the indexer uses HyperSync and neither is set. Pass --api-token "" to create the project without a token and add it to .env later. Until then the agent can still run codegen, type-check and run tests that use simulate, but tests that fetch real blocks fail with "An Envio API token is required".
  • To run pnpm dev locally, generate a token from the link above and set ENVIO_API_TOKEN in .env before starting the indexer.

See API Tokens and Environment Variables for full details.


Step 2. The Development Loop​

The skills cover config, schema, handlers, dynamic contracts, testing, and troubleshooting, so an agent can read them directly instead of inventing patterns. A productive loop looks like:

  1. Describe the behavior you want in plain English.
  2. Let the assistant edit config.yaml, schema.graphql, and src/handlers.
  3. Have it follow a test-driven loop: write a failing test with createTestIndexer(), implement the handler, then run pnpm test to capture and lock in snapshots. See the Testing guide for the full TDD workflow.
  4. Iterate on failures together.

The three files your agent will spend most of its time in:


Step 3. Migrating an Existing Indexer​

If you're porting from The Graph, Ponder, or another indexing framework, start with the AI migration workflow. It scales much better than hand-editing handlers.


Step 4. Deploy Programmatically with envio-cloud​

Once your indexer runs locally, the envio-cloud CLI lets an assistant (or a CI job) deploy and manage the hosted indexer without opening the dashboard. Envio Cloud builds from GitHub, so the assistant deploys by pushing a commit.

Two steps need you in a browser, once: sign in at envio.dev with GitHub, and install the Envio Deployments GitHub App on the repository. After that, an agent can run the loop:

npm install -g envio-cloud

envio-cloud login # uses ENVIO_GITHUB_TOKEN or a signed-in gh CLI, else opens a browser

# envio init creates the git repository but no commit or remote
git add -A && git commit -m "Initial indexer"
git branch -M main
git remote add origin https://github.com/<owner>/my-repo.git # an existing GitHub repository

envio-cloud config set-org <owner> # the repository's GitHub owner
envio-cloud repos -o json # my-repo must be listed
envio-cloud indexer add --name my-indexer --repo my-repo --branch main --yes
envio-cloud indexer get my-indexer -o json | jq -e .data # add can exit 0 on failure, so check
git push -u origin main
COMMIT=$(git rev-parse HEAD | cut -c1-7)
envio-cloud indexer commits my-indexer -o json # did the commit deploy?
envio-cloud deployment logs my-indexer $COMMIT --build
envio-cloud deployment status my-indexer $COMMIT --watch-till-synced --timeout 100s
  • Without a token or a signed-in gh CLI, envio-cloud login prints a link and waits until you approve it in a browser. See Log In for running it from an agent.
  • Set the organisation to the GitHub user or organisation that owns the repository. Otherwise the CLI uses your own GitHub account, and a repository owned by an organisation isn't found.
  • Envio Cloud identifies a deployment by the first 7 characters of its commit hash.
  • Pass --yes, or indexer add waits for a confirmation. Set --branch to the branch you push: the default is envio.
  • --watch-till-synced exits once every chain is ready. --timeout bounds the wait: keep it below your agent's tool-call time limit. When it runs out, the command exits with code 124 (not synced yet), so run it again.

Most commands support -o json, which makes it easy for assistants and scripts to parse results. See Deploy From an Agent or CI for commit statuses, JSON shapes and exit codes.