Skip to main content

Quickstart

This 5-minute tutorial shows you how to grab a Fuel Squid SDK indexer template. At the end you’ll have a complete blockchain indexer that serves counts of LOG_DATA receipts from all Fuel contracts.

What you’ll get

Your Fuel indexer (squid) will:
  • Fetch all historical LOG_DATA receipts starting from a given block
  • Maintain a count of such receipts for each contract in a local PostgreSQL database
  • Start a GraphQL server with a rich API to query this data
This tutorial focuses on Fuel. For other chains, see the EVM Quickstart or Solana Quickstart.

Prerequisites

Before you begin, ensure you have:
1

(Optional) 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 squid project from the Fuel example:
sqd init hello-squid -t https://github.com/subsquid-labs/fuel-example
cd hello-squid
or, if you skipped the installation of Squid CLI
git clone https://github.com/subsquid-labs/fuel-example hello-squid
cd hello-squid
3

Inspect the project structure

Explore the project structure:
src/
├── main.ts
└── model
    ├── contract.model.ts
    └── index.ts
Key files explained: - src/model/ - TypeORM model classes used in database operations - main.ts - Main executable containing data retrieval configuration and processing logic
The main.ts file first defines the data source object and configures its data retrieval options:
main.ts
// First we create a DataSource - the component that
// defines what data we need and where to get it
const dataSource = new DataSourceBuilder()
  // Provide a Subsquid Network Gateway URL
  .setGateway('https://v2.archive.subsquid.io/network/fuel-mainnet')
  // Subsquid Network is always about 10000 blocks behind the head.
  // We must use a regular GraphQL endpoint to get through
  // the last mile and stay on top of the chain.
  // This is a limitation, and we promise to lift it in the future!
  .setGraphql({
    url: 'https://mainnet.fuel.network/v1/graphql',
    strideConcurrency: 3,
    strideSize: 30
  })
  // Block data returned by the data source has the following structure:
  //
  // interface Block {
  //   header: BlockHeader
  //   receipts: Receipt[]
  //   transactions: Transaction[]
  //   inputs: Input[]
  //   outputs: Output[]
  // }
  //
  // For each block item we can specify a set of fields
  //  we want to fetch via the `.setFields()` method.
  // Think about it as of an SQL projection.
  //
  // Accurate selection of only the required fields
  // can have a notable positive impact on performance
  // when the data is sourced from Subsquid Network.
  //
  // We do it below only for illustration as all fields we've
  // selected are fetched by default.
  //
  // It is possible to override default selection by setting
  // the flags for undesirable fields to `false`.
  .setFields({
    receipt: {
      contract: true,
      receiptType: true
    }
  })
  // We request items via `.addXxx()` methods.
  //
  // Each `.addXxx()` method accepts item selection criteria
  // and also allows to request related items.
  .addReceipt({
    type: ['LOG_DATA']
  })
  .build()
Next, main.ts defines the data processing and storage logic. Data processing is defined in the batch handler, the callback that the run() function as its final argument:
main.ts
// Below we create a `TypeormDatabase`.
//
// It provides restricted subset of [TypeORM EntityManager API](https://typeorm.io/working-with-entity-manager)
// as a persistent storage interface and works with any Postgres-compatible database.
//
// Note, that we don't pass any database connection parameters.
// That's because `TypeormDatabase` expects a certain project structure
// and environment variables to pick everything it needs by convention.
// Companion `@subsquid/typeorm-migration` tool works in the same way.
//
// For full configuration details please consult
// https://github.com/subsquid/squid-sdk/blob/278195bd5a5ed0a9e24bfb99ee7bbb86ff94ccb3/typeorm/typeorm-config/src/config.ts#L21
const database = new TypeormDatabase()

// Now we are ready to start processing the data
run(dataSource, database, async ctx => {
  // Block items that we get from `ctx.blocks` are flat JS objects.
  //
  // We can use `augmentBlock()` function from `@subsquid/fuel-objects`
  // to enrich block items with references to related objects.
  let contracts: Map<String, Contract> = new Map()

  let blocks = ctx.blocks.map(augmentBlock)

  for (let block of blocks) {
    for (let receipt of block.receipts) {
      if (receipt.receiptType == 'LOG_DATA' && receipt.contract != null) {
        let contract = contracts.get(receipt.contract)
        if (!contract) {
          contract = await ctx.store.findOne(Contract, {where: {id: receipt.contract}})
          if (!contract) {
            contract = new Contract({
              id: receipt.contract,
              logsCount: 0,
              foundAt: block.header.height
            })
          }
        }
        contract.logsCount += 1
        contracts.set(contract.id, contract)
      }
    }
  }

  ctx.store.upsert([...contracts.values()])
})
4

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.
5

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 blocks.
6

Start the GraphQL API

Start the GraphQL API to serve the transfer data:
npx squid-graphql-server
7

Query the data

You can now query your indexed data! Check it out at the GraphiQL playground at localhost:4350/graphql.
Last modified on December 17, 2025