Documentation
Utilities
Utility types

Utility types

To enable code reuse and maintain type safety for advanced use cases, Ponder offers utility types that are aware of your ponder.config.ts and ponder.schema.ts files.

Indexing function types

The "@/generated" module exports utility types that are useful for creating reusable helper functions in your indexing files.

EventNames

A union of all event names that are available from the contracts defined in ponder.config.ts.

src/helpers.ts
import { ponder, type EventNames } from "@/generated";
 
function helper(eventName: EventNames) {
  eventName;
  // ^? "Weth:Deposit" | "Weth:Withdraw" | "Weth:Approval | "Weth:Transfer"
}

Event

A generic type that optionally accepts an event name and returns the event object type for that event.

src/helpers.ts
import { ponder, type Event } from "@/generated";
 
function helper(event: Event<"Weth:Deposit">) {
  event;
  // ^? { 
  //      args: { dst: `0x${string}`; wad: bigint };
  //      block: Block;
  //      event: "Deposit";
  //      transaction: Transaction;
  //      log: Log;
  //    }  
}

If no event name is provided, Event is the union of all event types. This can be useful if all you need is the block, transaction, and log types which are the same for all events.

src/helpers.ts
import { ponder, type Event } from "@/generated";
 
function helper(event: Event) {
  event;
  // ^? { args: { dst: `0x${string}`; wad: bigint }; block: Block; event: "Deposit"; transaction: Transaction; log: Log; }
  //    | { args: { src: `0x${string}`; wad: bigint }; block: Block; event: "Withdraw"; transaction: Transaction; log: Log; }
  //    ...
}

Context

A generic type that optionally accepts an event name and returns the context object type.

src/helpers.ts
import { ponder, type Context } from "@/generated";
 
function helper(context: Context<"Weth:Deposit">) {
  event;
  // ^? { 
  //      network: { name: "mainnet"; chainId: 1; };
  //      client: ReadonlyClient;
  //      db: { Account: DatabaseModel<{ id: `0x${string}`; balance: bigint; }> };
  //      contracts: { weth9: { abi: ...; address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" } };
  //    }  
}

If no event name is provided, Context returns the union of all context types. This can be useful if all you need is the db or contracts types which are the same for all events.

IndexingFunctionArgs

A generic type that optionally accepts an event name and returns the indexing function argument type.

src/helpers.ts
import { ponder, type IndexingFunctionArgs } from "@/generated";
 
function helper(args: IndexingFunctionArgs<"Weth:Deposit">) {
  args;
  // ^? { 
  //      event: { ... };
  //      context: { ... };
  //    }
}

Like Event and Context, IndexingFunctionArgs returns the union of all indexing function argument types if no event name is provided.

Schema

A generic type that requires a table name from ponder.schema.ts and returns the type of a record in that table.

src/helpers.ts
import { ponder, type Schema } from "@/generated";
 
function helper(account: Schema<"Account">) {
  account;
  // ^? {
  //      id: bigint;
  //      balance: bigint;
  //      nickname: string;
  //      createdAt: number;
  //    }
}

Config types

The @ponder/core package exports a utility type for each option passed to createConfig().

ContractConfig

The type of a contract in createConfig().

ponder.config.ts
import type { ContractConfig } from "@/generated";
import { createConfig } from "@ponder/core";
import { Erc20Abi } from "./abis/Erc20Abi.ts";
 
const Erc20 = {
  network: "mainnet"
  abi: Erc20Abi,
  address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
} as const satisfies ContractConfig;
 
export default createConfig({
  networks: ...,
  contracts: {
    Erc20,
  },
});

NetworkConfig

The type of a network in createConfig().

ponder.config.ts
import type { NetworkConfig } from "@/generated";
import { createConfig } from "@ponder/core";
import { http } from "viem";
 
const mainnet = {
  chainId: 1,
  transport: http(process.env.PONDER_RPC_URL_1),
} as const satisfies NetworkConfig;
 
export default createConfig({
  networks: {
    mainnet,
  }
  contracts: ...,
});

BlockConfig

The type of a block source in createConfig().

ponder.config.ts
import type { BlockConfig } from "@/generated";
import { createConfig } from "@ponder/core";
 
const ChainlinkPriceOracle = {
  network: "mainnet",
  startBlock: 19_750_000,
  interval: 5,
} as const satisfies BlockConfig;
 
export default createConfig({
  networks: ...,
  blocks: {
    ChainlinkPriceOracle,
  },
});

DatabaseConfig

The type of a database in createConfig().

ponder.config.ts
import type { DatabaseConfig } from "@/generated";
import { createConfig } from "@ponder/core";
 
const database = {
  kind: "postgres",
  schema: "production"
} as const satisfies DatabaseConfig;
 
export default createConfig({
  networks: ...,
  contracts: ...,
  database,
});