Skip to main content

Fuel Quickstart

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

What you’ll build

Your Fuel indexer (squid) will:
  • Fetch historical Fuel receipts and transactions from the SQD Network
  • Decode Fuel-specific data structures
  • 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 Fuel. For other chains, see the EVM Quickstart or Solana 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 Fuel squid project:
sqd init hello-fuel-squid -t fuel
cd hello-fuel-squid
The template provides a pre-configured project structure for indexing Fuel receipts and transactions.
3

Inspect the project structure

Explore the ./src folder:
src/
├── main.ts
├── processor.ts
└── model
    ├── generated
   ├── index.ts
   └── receipt.model.ts
    └── index.ts
Key files explained: - src/model/ - TypeORM model classes auto-generated from schema.graphql for database operations - processor.ts - Processor configuration for data retrieval - main.ts - Main executable containing processing logic
The processor configuration for Fuel:
processor.ts
export const processor = new FuelBatchProcessor()
  // SQD Network gateway for Fuel
  .setGateway("https://v2.archive.subsquid.io/network/fuel-mainnet")
  // Optional RPC endpoint for real-time data
  .setRpcEndpoint("<fuel-rpc-endpoint>")
  // Configure block range
  .setBlockRange({ from: 1000000 })
  // Add receipts to index
  .addReceipt({
    type: ["CALL", "RETURN", "LOG"],
  })
  // Select fields to retrieve
  .setFields({
    receipt: {
      contract: true,
      data: true,
    },
    transaction: {
      id: true,
    },
  });
The data processing and storage logic:
main.ts
processor.run(new TypeormDatabase({ supportHotBlocks: true }), async (ctx) => {
  const receipts = [];

  for (let block of ctx.blocks) {
    for (let receipt of block.receipts) {
      // Process different receipt types
      if (receipt.type === "CALL" || receipt.type === "RETURN") {
        receipts.push(
          new Receipt({
            id: receipt.id,
            blockHeight: block.header.height,
            transactionId: receipt.getTransaction().id,
            type: receipt.type,
            contract: receipt.contract,
            data: receipt.data,
          })
        );
      }
    }
  }

  // Batch insert all receipts
  await ctx.store.save(receipts);
});
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 Fuel blocks.
6

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
7

Query the data

You can now query your indexed Fuel data! Try this example query in the GraphQL playground:
{
  receipts(limit: 10) {
    id
    blockHeight
    transactionId
    type
    contract
  }
}
Congratulations! You’ve successfully built and deployed your first Fuel blockchain indexer.