Skip to main content

Solana Quickstart

This 5-minute tutorial shows you how to build a Solana indexer using Squid SDK. You’ll create a complete blockchain indexer that fetches, decodes, and serves Solana program data.

What you’ll build

Your Solana indexer (squid) will:
  • Fetch historical Solana program instructions and transactions from the SQD Network
  • Save the data to a local PostgreSQL database
  • Start a GraphQL server with a rich API to query the indexed data
This tutorial focuses on Solana. For other chains, see the EVM Quickstart or Substrate Quickstart.

Prerequisites

Before you begin, ensure you have:
1

Install Squid CLI

Install the Squid CLI globally:
npm i -g @subsquid/cli
Verify installation by running sqd --version
Squid CLI is a multi-purpose utility tool for scaffolding and managing indexers, both locally and in SQD Cloud.
2

Scaffold the indexer project

Create a new Solana squid project:
sqd init hello-solana-squid -t solana
cd hello-solana-squid
The template provides a pre-configured project structure for indexing Solana programs.
3

Install Portal API package

Portal support requires the @portal-api version of the Solana processor package:
npm i @subsquid/solana-stream@portal-api
This version includes Portal-specific features and optimizations for improved performance.
4

Inspect the project structure

Explore the ./src folder:
src/
├── main.ts
└── model
    ├── generated
   ├── index.ts
   └── transfer.model.ts
    └── index.ts
Key files explained: - src/model/ - TypeORM model classes auto-generated from schema.graphql for database operations - main.ts - Main executable containing data retrieval configuration and processing logic
The main.ts file contains the core processor configuration for Solana:
main.ts
const processor = new SolanaBatchProcessor()
  // Portal for Solana
  .setPortal("https://portal.sqd.dev/datasets/solana-mainnet")
  // Optional RPC endpoint for real-time data
  .setRpcEndpoint("<solana-rpc-endpoint>")
  // Configure which data to fetch
  .setBlockRange({ from: 100000000 })
  // Add instructions to index
  .addInstruction({
    programId: ["<program-id>"],
    isCommitted: true,
  })
  // Select fields to retrieve
  .setFields({
    instruction: {
      programId: true,
      accounts: true,
      data: true,
    },
    transaction: {
      signatures: true,
    },
  });
The data processing and storage logic:
main.ts
processor.run(new TypeormDatabase({ supportHotBlocks: true }), async (ctx) => {
  const transfers = [];

  for (let block of ctx.blocks) {
    for (let instruction of block.instructions) {
      // Decode program instruction data
      const data = decodeInstructionData(instruction.data);

      transfers.push({
        id: instruction.id,
        slot: block.header.slot,
        programId: instruction.programId,
        data: data,
        signature: instruction.getTransaction().signatures[0],
      });
    }
  }

  // Batch insert all transfers
  await ctx.store.insert(transfers);
});
5

Install dependencies and build

Install dependencies and build the project:
npm i
npm run build
Verify the build completed successfully by checking for the lib/ directory.
6

Start the database and processor

The processor continuously fetches data, decodes it, and stores it in PostgreSQL. All logic is defined in main.ts and is fully customizable.First, start a local PostgreSQL database (the template includes a Docker Compose file):
docker compose up -d
The processor connects to PostgreSQL using connection parameters from .env. Ensure the database is running before proceeding.
Apply database migrations:
npx squid-typeorm-migration apply
Then start the processor:
node -r dotenv/config lib/main.js
The indexer is now running and will begin processing Solana blocks.
7

Start the GraphQL API

Start the GraphQL API to serve the indexed data:
npx squid-graphql-server
The GraphQL playground is available at localhost:4350/graphql
8

Query the data

You can now query your indexed Solana data! Try this example query in the GraphQL playground:
{
  transfers(limit: 10) {
    id
    slot
    programId
    signature
  }
}
Congratulations! You’ve successfully built and deployed your first Solana blockchain indexer.