Pipes SDK is a highly customizable blockchain indexing library made by SQD. This repo is a collection of various examples of its usage.
At src/basics folder of this repo you'll find a sequence of examples highlighting core concepts and basic functionality of the Pipes SDK. Follow BASICS.md to learn more.
src/advanced contains examples showcasing the less common features. It significantly overlaps with the examples folder of the Pipes SDK package repo which doubles as a collection of ad-hoc tests. Here are some topics covered:
- user side raw data caching
- profiling (throughout the examples)
- indexing factory contracts
- customizing the metrics
- stateful transforms: in-RAM rolling window with portal warm-up
- stateful transforms writing to Postgres — stateless approach
- stateful transforms writing to Postgres — in-memory approach
These should run in the same manner as basic examples do: start with BASICS.md/Quickstart then run the example files with bun or ts-node.
Examples 11 and 12 demonstrate two approaches to storing both transformer state and final data in the same PostgreSQL database using drizzleTarget.
Start Postgres:
docker compose up -d test_postgresThis starts a Postgres 17 instance on localhost:5432 (user: postgres, password: postgres, database: postgres). Wait for the healthcheck to pass before running the examples.
Schema / migrations:
Both examples call onStart to run CREATE TABLE IF NOT EXISTS statements when the indexer first connects. This is sufficient for running the examples as-is.
For production use, replace the onStart DDL with drizzle-kit migrations:
npx drizzle-kit generate # generate SQL migration files from your schema
npx drizzle-kit migrate # apply pending migrationsRun example 11 (stateless — reads state from Postgres each batch):
DB_URL=postgresql://postgres:postgres@localhost:5432/postgres \
npx ts-node src/advanced/evm/11.stateful-transforms-postgres-stateless.example.tsRun example 12 (in-memory — loads state once at startup, updates in RAM):
DB_URL=postgresql://postgres:postgres@localhost:5432/postgres \
npx ts-node src/advanced/evm/12.stateful-transforms-postgres-in-memory.example.tsBoth examples index the SQD token on Arbitrum One and maintain a token_balances table (running ERC-20 balance per address) and a transfer_counts table (number of outbound transfers per address). They are interchangeable — the on-disk schema is identical; only the in-process state management differs.
A collection of Pipes SDK project intended as starting points:
These are related to the indexers that SQD uses internally:
- The stablecoins indexer that sends the data via Server Side Events for further processing
- Simple indexer of ERC20 transfers.