TLDR:Documentation Index
Fetch the complete documentation index at: https://chainstack-mintlify-flesh-empty-pages.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
- You’ll build a complete blockchain indexing backend using Ponder and Chainstack nodes.
- You’ll create a Ponder project that indexes ERC-20 token transfers and balances across multiple chains.
- You’ll configure Ponder to use Chainstack RPC endpoints for reliable data fetching.
- By the end, you’ll have a production-ready GraphQL API for querying blockchain data with hot reloading and type safety.
Main article
In this tutorial, you will:- Create a Ponder project that indexes blockchain data from multiple networks.
- Configure Ponder to use Chainstack nodes for reliable, high-performance data access.
- Build a schema to track ERC-20 token transfers, balances, and holder statistics.
- Deploy indexing functions that process blockchain events in real-time.
- Query your data through Ponder’s auto-generated GraphQL API.
Prerequisites
- Chainstack account to deploy blockchain nodes
- Node.js version 18.14 or higher
- pnpm package manager (recommended)
Dependencies
- ponder: ^0.11.0
- viem: ^2.30.0
- typescript: ^5.0.0
Step-by-step
Create a public chain project
See Create a project.Join blockchain networks
For this tutorial, we’ll index data from multiple chains. Join the following networks:- Ethereum - for established DeFi protocols
- Polygon - for high-volume, low-cost transactions
- Base - for modern L2 applications
Get your node access and credentials
See View node access and credentials. You’ll need the RPC endpoints for each network you joined.Create a new Ponder project
-
Create a new Ponder project using the CLI:
This will prompt you to choose a template. For this tutorial, select “ERC-20” as it provides a good starting point for token indexing.
-
Navigate to your project directory:
-
Install dependencies:
Configure environment variables
-
Create a
.env.localfile in your project root:Replace the placeholder values with your actual Chainstack endpoints.Environment variable naming
Ponder uses the patternPONDER_RPC_URL_{CHAIN_ID}for RPC endpoints. The chain IDs are:- Ethereum: 1
- Polygon: 137
- Base: 8453
Configure Ponder for multiple chains
-
Edit
ponder.config.tsto configure your chains and contracts:This configuration sets up Ponder to index USDC transfers across three different chains using your Chainstack nodes.Start block optimization
Setting appropriate start blocks is crucial for performance. Choose blocks close to when your contracts were deployed or when interesting activity began.
Define your database schema
-
Edit
ponder.schema.tsto define the data structure you want to track:This schema defines three tables:- transfers: Individual transfer events
- balances: Current token balances per account
- tokenStats: Aggregate statistics per token contract
Write indexing functions
-
Create indexing functions to process Transfer events. Replace the contents of
src/index.ts:This indexing logic:- Records every transfer event across all three chains
- Maintains real-time balance tracking for all accounts
- Handles historical data gaps when starting from an arbitrary block (accounts may have balances from before the start block)
- Tracks holder counts by detecting when balances go from zero to positive (new holder) or positive to zero (holder exit)
- Calculates aggregate statistics including transfer volume and holder statistics per token contract
Start the development server
-
Start the Ponder development server:
You should see output similar to:
Development features
Ponder’s development server includes:- Hot reloading when you change config, schema, or indexing functions
- Real-time progress monitoring and error reporting
- Built-in GraphQL playground at http://localhost:42069
- Open your browser to http://localhost:42069 to access the GraphQL playground.
Query your indexed data
-
In the GraphQL playground, try these example queries:
Get recent transfers across all chains:
Get top holders for a specific token:
Deploy to production
-
For production deployment, you’ll need a PostgreSQL database. Update your
.env.local: -
Build your Ponder application:
-
Start the production server:
Your Ponder application will be available at the configured port with a production-ready GraphQL API.
Conclusion
This tutorial guided you through building a comprehensive blockchain indexing backend using Ponder and Chainstack. You’ve created a system that:- Indexes data from multiple blockchain networks simultaneously
- Provides type-safe, real-time data processing
- Offers a production-ready GraphQL API
- Scales efficiently with Chainstack’s reliable infrastructure
