Skip to content

enoldev/pump-fun-substreams-js-app

Repository files navigation

Pump.fun JS Substreams Application

This is a NextJS sample application using the Substream JS library to consume data from the Pump.fun program in Solana Mainnet.

The application is getting all the TradeEvent objects from the Pump.fun Substreams package.

In this directory you can find an example of a NextJS application using the Substreams JS library with Typescript.

The application uses the basic template provided by the create-next-app utility.

Getting Started

  1. Install the dependencies:
npm install
  1. Open the constants.js file, all the configuration variables of the application. Then, update the TOKEN variable with your Subtreams API token. If you have previously run the Substreams CLI, you can find the token at the $SUBSTREAMS_API_TOKEN environment variable of your system.
const TOKEN = "<SUBSTREAMS-TOKEN>"
  1. You can run the application just like a normal NextJS application:
npm run dev

The application will be now available at the specified port.

Understanding the Code

  1. All the code related to Substreams is in the substreams directory. The startSubstreams function of the main.js file contains the entrypoint of the Substreams logic.

  2. The startSubstreams function expects several handlers (i.e. functions), which are defined in the types.ts file. Every function handles a different response type sent by the Substreams provider:

  • BlockScopedDataHandler: executed when a new block is sent from the Substreams provider.
  • BlockUndoSignalHandler: executed after a fork has happened.
  • ModuleProgressHandler: executed when a new progress message is sent.
export type BlockScopedDataHandler = (response: BlockScopedData, registry: IMessageTypeRegistry) => Promise<void>;
export type BlockUndoSignalHandler = (response: BlockUndoSignal) => Promise<void>;
export type ModuleProgressHandler = (response: ModulesProgress) => Promise<void>;

You can get more information about the different messages sent by the Substreams provider in the docs.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published