Coder Social home page Coder Social logo

brightiron / ponder Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ponder-sh/ponder

0.0 0.0 0.0 22.07 MB

A backend framework for crypto apps

Home Page: https://ponder.sh

License: MIT License

Shell 0.01% JavaScript 1.57% TypeScript 98.06% Solidity 0.36%

ponder's Introduction

Ponder

CI status Version Telegram chat License

Ponder is an open-source framework for blockchain application backends.

Documentation

Visit ponder.sh for documentation, guides, and the API reference.

Support

Join Ponder's telegram chat for support, feedback, and general chatter.

Features

✅  Local development server with hot reloading
✅  create-ponder CLI tool to get started from an Etherscan link or Graph Protocol subgraph
✅  End-to-end type safety using viem and ABIType
✅  Autogenerated GraphQL API
✅  Easy to deploy anywhere using Node.js/Docker
✅  Supports all Ethereum-based blockchains, including test nodes like Anvil
✅  Index events from multiple chains in the same app
✅  Reconciles chain reorganization
✅  Factory contracts
🏗️  Process transactions calls (in addition to logs)
🏗️  Run effects (e.g. send an API request) in indexing code

Quickstart

1. Run create-ponder

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

npm init ponder@latest
# or
pnpm create ponder
# or
yarn create ponder

2. 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.

npm run dev
# or
pnpm dev
# or
yarn dev

3. Add contracts & networks

Ponder fetches event logs for the contracts added to ponder.config.ts, and passes those events to the indexing functions you write.

// ponder.config.ts
import { http } from "viem";

import { BaseRegistrarAbi } from "./abis/BaseRegistrar";

export const config = {
  networks: [
    {
      name: "mainnet",
      chainId: 1,
      transport: http("https://eth-mainnet.g.alchemy.com/v2/..."),
    },
  ],
  contracts: [
    {
      name: "BaseRegistrar",
      network: "mainnet",
      abi: BaseRegistrarAbi,
      address: "0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85",
      startBlock: 9380410,
    },
  ],
};

4. Define your schema

The ponder.schema.ts file contains the database schema, and defines the shape data that the GraphQL API serves.

// ponder.schema.ts

import { createSchema } from "@ponder/core";

export default createSchema((p) => ({
  EnsName: p.createTable({
    id: p.string(),
    name: p.string(),
    owner: p.string(),
    registeredAt: p.int(),
  }),
}));

5. Write indexing functions

Files in the src/ directory contain indexing functions, which are TypeScript functions that process a contract event. The purpose of these functions is to insert data into the entity store.

// src/BaseRegistrar.ts

import { ponder } from "@/generated";

ponder.on("BaseRegistrar:NameRegistered", async ({ event, context }) => {
  const { EnsName } = context.entities;
  const { name, owner } = event.params;

  await EnsName.create({
    id: `${name}-${owner}`,
    data: {
      name: name,
      owner: owner,
      registeredAt: event.block.timestamp,
    },
  });
});

See the create & update records docs for a detailed guide on writing indexing functions.

6. Query the GraphQL API

Ponder automatically generates a frontend-ready GraphQL API based on your project's schema.graphql. The API serves the data that you inserted in your indexing functions.

{
  ensNames(first: 2) {
    name
    owner
    registeredAt
  }
}
{
  "ensNames": [
    {
      "name": "vitalik.eth",
      "owner": "0x0904Dac3347eA47d208F3Fd67402D039a3b99859",
      "registeredAt": 1580345271
    },
    {
      "name": "joe.eth",
      "owner": "0x6109DD117AA5486605FC85e040ab00163a75c662",
      "registeredAt": 1580754710
    }
  ]
}

That's it! Visit ponder.sh for documentation, guides for deploying to production, and the API reference.

Contributing

If you're interested in contributing to Ponder, please read the contribution guide.

Packages

  • @ponder/core
  • create-ponder
  • eslint-config-ponder

About

Ponder is MIT-licensed open-source software.

ponder's People

Contributors

0xolias avatar kyscott18 avatar github-actions[bot] avatar eliobricenov avatar bankisan avatar o-az avatar grayleonard avatar holic avatar r0ohafza avatar arberx avatar cjpais avatar cbergz avatar carletex avatar freezyex avatar jrfrantz avatar jaylmiller avatar 0xjjpa avatar slokh avatar fmhall avatar salieflewis avatar saribmah avatar gosuto-inzasheru avatar jcheese1 avatar k-xo avatar payton avatar pyk avatar shafu0x avatar smartcontracts avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.