Skip to main content

Claude/ChatGPT Prompt to Build a Blockchain Event Indexer

Build an event indexing service that listens to contract events, handles reorgs and backfill, stores to a database, and serves a GraphQL API.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
Build a blockchain event indexing service for Uniswap V3-style DEX with multiple pools deployed on Ethereum mainnet. The indexer processes Swap, Mint, Burn, Collect, PoolCreated, Transfer events and serves data to analytics dashboard, trading interface, and portfolio tracker. Implement: 1) Event listener using ethers.js v6 or viem — connect to Alchemy with WebSocket for subscriptions, subscribe to contract events with proper filter topics, and handle chain reorganizations by tracking 12 blocks block confirmations before marking events as finalized. 2) Historical backfill: index all past events from block contract deployment block to current head using batch eth_getLogs with 2000 blocks per request block ranges to avoid RPC timeouts. Store progress checkpoint to resume after interruption. 3) Data transformation: map raw event data to normalized tables with transaction hash, block number, timestamp, and decoded event data — decode event parameters, resolve ENS names for addresses, fetch token metadata, and compute USD value at time of swap, 24h volume, price impact percentage derived fields. 4) Database layer using PostgreSQL with TimescaleDB extension for time-series data — schema design with tables for swaps, liquidity_events, pools, tokens, daily_stats, indexes on block_number, timestamp, pool_address, token pair, trader address, and materialized views for 24h volume per pool, TVL snapshots, top traders by volume. 5) API layer: GraphQL with Apollo Server with queries for swaps by pool, user trade history, pool statistics, token price history — support pagination, filtering by time range, pool address, minimum amount, token pair, and sorting. Include real-time subscription for new events using GraphQL subscriptions via WebSocket. 6) Reliability: handle RPC disconnection, chain reorganization, malformed event data, database connection loss — RPC provider failover to Infura as secondary, public RPC as last resort, automatic retry for failed event processing, dead letter queue for unprocessable events, and health check endpoint. 7) Performance: process 500 events per second, with Redis for recent queries and aggregation results with 60-second TTL caching for frequently accessed queries.

What this prompt does

This prompt designs a blockchain event indexer — the underestimated data layer behind on-chain dashboards. You set the [contract_type], [target_chain], [event_list], and [consumer_applications], and it builds a listener using [web3_library] against [rpc_provider] that handles reorgs by waiting [confirmation_depth] confirmations, plus historical backfill, data transformation, a database layer, an API, reliability handling, and performance targets.

The structure works because naive indexers break exactly where this prompt forces design effort. Backfill from [start_block] uses [batch_size] ranges with a resumable checkpoint, transformation maps raw events to [database_schema] and computes [derived_fields], storage uses [database] with indexes on [indexed_columns], the API ([api_type]) serves [api_queries] with real-time updates via [realtime_method], and reliability covers [failure_scenarios] including failover to [backup_rpc] — the gaps that silently corrupt indexed data. The [consumer_applications] and [target_throughput] inputs shape the schema and caching, so the design fits the analytics dashboards and trading interfaces that will actually query it.

When to use it

  • You are building the data layer behind an on-chain dashboard or analytics tool
  • You need reorg handling so finalized data is not built on orphaned blocks
  • You need resumable backfill from [start_block] that survives interruption
  • You want a queryable [api_type] over indexed events with pagination and filtering
  • You need RPC failover to [backup_rpc] and retry handling for reliability
  • You want aggregation views like 24h volume precomputed for fast queries
  • You want real-time updates pushed via [realtime_method]

Example output

Expect a service design: a listener using [web3_library] subscribing to [event_list] with [confirmation_depth] reorg handling, a backfill routine iterating [batch_size] block ranges with a saved checkpoint, a transformation layer mapping events to [database_schema] and computing [derived_fields], a [database] schema with tables [table_list], indexes on [indexed_columns], and materialized views for [aggregation_queries], an [api_type] exposing [api_queries] with filtering by [filter_params] and [realtime_method] subscriptions, plus reliability handling for [failure_scenarios] with [backup_rpc] failover and a health endpoint. A caching layer using [caching_strategy] is described for the queries that get hit most often.

Pro tips

  • Set [confirmation_depth] to your chain's reorg reality; too shallow indexes orphaned blocks, too deep adds latency to finalized data
  • Always make backfill resumable from a checkpoint — indexing from [start_block] can take hours, and a crash without checkpointing means starting over
  • Tune [batch_size] to avoid RPC timeouts; large ranges fail on busy contracts, so smaller eth_getLogs windows are safer
  • Plan [indexed_columns] around your real [api_queries], since the database indexes are what keep queries fast at volume
  • Precompute [aggregation_queries] into materialized views rather than calculating them on every request under load
  • Configure [backup_rpc] failover from the start; single-provider indexers stall the moment that provider has an incident
  • Validate [derived_fields] like USD-at-time-of-swap carefully, because a wrong price source quietly corrupts every downstream aggregation

Frequently Asked Questions

How does it handle chain reorganizations?
It tracks `[confirmation_depth]` block confirmations before marking events as finalized, so data is not built on blocks that later get orphaned. When a reorg occurs within that window, the affected events are reprocessed rather than left stale in the database.
What happens if the indexer crashes mid-backfill?
Backfill stores a progress checkpoint, so it resumes from the last completed block range rather than restarting from `[start_block]`. This matters because indexing a busy contract's full history can take hours, and re-indexing from scratch wastes RPC quota and time.
Which database does it use?
The default `[database]` is PostgreSQL with the TimescaleDB extension for time-series data, with tables `[table_list]` and indexes on `[indexed_columns]`. You can substitute another store, but the schema design and aggregation views assume a relational, query-friendly backend.
Does it serve data in real time?
Yes. The `[api_type]`, typically GraphQL, exposes `[realtime_method]` such as subscriptions over WebSocket, pushing new events to consumers as they are indexed. It also supports paginated, filtered historical queries for `[consumer_applications]` that need to query past data.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Blockchain & Web3 Development Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support