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.
- Install the dependencies:
npm install
- Open the
constants.js
file, all the configuration variables of the application. Then, update theTOKEN
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>"
- You can run the application just like a normal NextJS application:
npm run dev
The application will be now available at the specified port.
-
All the code related to Substreams is in the
substreams
directory. ThestartSubstreams
function of themain.js
file contains the entrypoint of the Substreams logic. -
The
startSubstreams
function expects several handlers (i.e. functions), which are defined in thetypes.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.