Create a new project

Quickstart

Run the create-ponder CLI tool

pnpm create ponder

You will be asked for a project name, and if you are using a template (recommended). The tool will then create a project directory, install dependencies, and initialize a git repository.

💡

If you're building a Ponder app for a contract that has already been deployed, use the Etherscan contract link template.

Start the development server

Just like Next.js and Vite, Ponder has a development server that automatically reloads when you save changes in any project file. It also prints console.log statements and errors encountered while running your code.

First, cd into your project directory, then start the server.

pnpm dev

Add an RPC URL

Ponder fetches data using the standard Ethereum RPC API. To get started, you'll need an RPC URL from a provider like Alchemy or Infura.

Open up .env.local and paste in RPC URLs for any networks that your project uses:

.env.local
PONDER_RPC_URL_1 = "https://eth-mainnet.g.alchemy.com/v2/..."

Define your schema

The schema.graphql file defines the entity data that the GraphQL API will serve. Any types marked with the @entity directive will become available as entity models in your handler functions.

Using schema.graphql, Ponder automatically generates a GraphQL API that serves entity data.

Write event handlers

Files in the src/ directory contain event handlers. Event handlers are TypeScript functions that accept a contract event and insert data into the entity store.

Here's a sample event handler for an ERC721 Transfer event.

src/MyNftContract.ts
import { ponder } from "../generated";
 
ponder.on("MyNftContract:Transfer", async ({ event, context }) => {
  const { Token } = context.entities;
  const { MyNftContract } = context.contracts;
 
  // Get an entity object
  const token = await Token.get(event.params.id);
 
  // Call a contract read function
  const tokenUri = await MyNftContract.tokenUri(token.id);
 
  // ...
});

Query the GraphQL API

As you write your event handlers and start inserting entity data, open the GraphiQL interface at http://localhost:42069/graphql to explore your GraphQL API locally. Any changes you make to your schema.graphql file will be reflected here.