> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sqd.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Get a Substrate blockchain indexer in 5 minutes with Squid SDK

# Quickstart

This 5-minute tutorial shows you how to grab a Substrate Squid SDK indexer template. At the end you'll have a complete blockchain indexer that fetches, decodes, and serves KSM transfers data from Kusama.

## What you'll get

Your Substrate indexer (squid) will:

* Fetch all historical KSM transfers on Kusama
* Save the data to a local PostgreSQL database
* Start a GraphQL server with a rich API to query the indexed transfers

<Note>
  This tutorial focuses on Substrate. For other chains, see the [EVM Quickstart](/en/sdk/squid-sdk/evm/quickstart) or [Solana Quickstart](/en/sdk/squid-sdk/solana/quickstart).
</Note>

## Prerequisites

Before you begin, ensure you have:

* **Node.js v20+** - [Download here](https://nodejs.org/)
* **Git** - [Download here](https://git-scm.com/)
* **Docker** - [Download here](https://www.docker.com/) (for running PostgreSQL)
* **WSL** (Windows only) - [Install WSL](https://learn.microsoft.com/en-us/windows/wsl/install)

<Steps>
  <Step title="(Optional) Install Squid CLI">
    Install the Squid CLI globally:

    ```bash theme={"system"}
    npm i -g @subsquid/cli@latest
    ```

    <Check>Verify installation by running `sqd --version`</Check>

    <Tip>
      Squid CLI is a multi-purpose utility tool for scaffolding and managing
      indexers, both locally and in SQD Cloud.
    </Tip>
  </Step>

  <Step title="Scaffold the indexer project">
    Create a new squid project from the `substrate` template:

    ```bash theme={"system"}
    sqd init hello-squid -t substrate
    cd hello-squid
    ```

    or, if you skipped the installation of Squid CLI

    ```bash theme={"system"}
    git clone https://github.com/subsquid-labs/squid-substrate-template hello-squid
    cd hello-squid
    ```
  </Step>

  <Step title="Inspect the project structure">
    Explore the project structure:

    ```bash theme={"system"}
    src/
    ├── main.ts
    ├── model
    │   ├── generated
    │   │   ├── account.model.ts
    │   │   ├── index.ts
    │   │   ├── marshal.ts
    │   │   └── transfer.model.ts
    │   └── index.ts
    ├── processor.ts
    └── types
        ├── balances
        │   └── events.ts
        ├── events.ts
        ├── index.ts
        ├── support.ts
        ├── v1020.ts
        ├── v1050.ts
        └── v9130.ts
    ```

    <Info>
      **Key files explained:** - `src/types` - Utility modules generated
      for interfacing the `balances` pallet data. - `src/model/` - TypeORM
      model classes used in database operations - `processor.ts` - Data
      retrieval configuration - `main.ts` - Main executable containing
      processing logic
    </Info>

    The `processor.ts` file defines the `SubstrateBatchProcessor` object and configures data retrieval:

    ```typescript processor.ts theme={"system"}
    export const processor = new SubstrateBatchProcessor()
      // SQD gateway is the faster source of historical data.
      .setGateway({
        url: 'https://v2.archive.subsquid.io/network/kusama',
        apiKey: process.env.SQD_API_KEY,
      })
      // Chain RPC endpoint is required on Substrate for metadata and real-time updates
      .setRpcEndpoint({
        // Set via .env for local runs or via secrets when deploying to Subsquid Cloud
        // https://docs.subsquid.io/deploy-squid/env-variables/
        url: assertNotNull(process.env.RPC_KUSAMA_HTTP, 'No RPC endpoint supplied'),
        // More RPC connection options at https://docs.subsquid.io/substrate-indexing/setup/general/#set-data-source
        rateLimit: 10
      })
      .addEvent({
        name: [events.balances.transfer.name],
        extrinsic: true
      })
      .setFields({
        event: {
          args: true
        },
        extrinsic: {
          hash: true,
          fee: true
        },
        block: {
          timestamp: true
        }
      })
    ```

    Next, `main.ts` defines the data processing and storage logic. Data processing is defined in the *batch handler*, the callback that the `processor.run()` main call receives as its final argument:

    ```typescript main.ts theme={"system"}
    processor.run(new TypeormDatabase({supportHotBlocks: true}), async (ctx) => {
      let transferEvents: TransferEvent[] = getTransferEvents(ctx)

      let accounts: Map<string, Account> = await createAccounts(ctx, transferEvents)
      let transfers: Transfer[] = createTransfers(transferEvents, accounts)

      await ctx.store.upsert([...accounts.values()])
      await ctx.store.insert(transfers)
    })
    ```

    See the [full file](https://github.com/subsquid-labs/squid-substrate-template/blob/main/src/main.ts) for details.
  </Step>

  <Step title="Install dependencies and build">
    Install dependencies and build the project:

    ```bash theme={"system"}
    npm i
    npm install @subsquid/substrate-processor@latest
    npm install --save-dev @subsquid/substrate-typegen@latest
    npm run build
    ```

    <Check>
      Verify the build completed successfully by checking for the `lib/` directory.
    </Check>
  </Step>

  <Step title="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.

    Add your SQD Network API key to `.env` before starting the processor:

    ```dotenv theme={"system"}
    SQD_API_KEY=<YOUR_SQD_NETWORK_API_KEY>
    ```

    First, start a local PostgreSQL database (the template includes a Docker Compose file):

    ```bash theme={"system"}
    docker compose up -d
    ```

    <Warning>
      The processor connects to PostgreSQL using connection parameters from `.env`.
      Ensure the database is running before proceeding.
    </Warning>

    Apply database migrations:

    ```bash theme={"system"}
    npx squid-typeorm-migration apply
    ```

    Then start the processor:

    ```bash theme={"system"}
    node -r dotenv/config lib/main.js
    ```

    <Check>The indexer is now running and will begin processing blocks.</Check>
  </Step>

  <Step title="Start the GraphQL API">
    Start the GraphQL API to serve the transfer data:

    ```bash theme={"system"}
    npx squid-graphql-server
    ```
  </Step>

  <Step title="Query the data">
    You can now query your indexed data! Check it out at the GraphiQL playground at [localhost:4350/graphql](http://localhost:4350/graphql).
  </Step>
</Steps>
