Skip to content

flair-sdk/starter-boilerplate

Repository files navigation

Indexing Starter Boilerplate

Flair join chat

This repository contains boilerplate scripts, abis and schema for indexing (catch all contract events/transactions) and syncing it to your own database.

Table of Contents

Getting Started

1️⃣ Clone this repo:

git clone https://github.com/flair-sdk/starter-boilerplate.git my-indexer
cd my-indexer && pnpm i

or open in gitpod:

Open in Gitpod

2️⃣ Authenticate:

pnpm flair auth

3️⃣ Config and ABI:

There are config.dev.json and config.prod.json sample configs for dev and prod clusters.

Set a globally unique namespace in each config file (recommended to use {ORG_NAME}-{ENV}; e.g sushiswap-dev or sushiswap-prod):

# Setting configs for dev testing
cp config.dev.json config.json

# Or setting it for production
cp config.prod.json config.json

Also add the ABI of your contract under src/abis/abi.json.

4️⃣ Deploy your indexer:

pnpm generate-and-deploy

5️⃣ Backfill some historical data:

# You can backfill for a specific block number, for all relevant events and transactions:
pnpm flair backfill --chain 1 -b 17998797

# Or backfill for the recent data of your contracts in the last 5 minutes:
pnpm flair backfill --chain 1 --min-timestamp="5 mins ago"

6️⃣ Look at the logs:

pnpm flair logs --full --watch

pnpm flair logs --full -tag Level=error
pnpm flair logs --full -tag Level=warn

pnpm flair logs --full -tag ProcessorId=basic-events
pnpm flair logs --full -tag ProcessorId=basic-transactions --watch
pnpm flair logs --full -tag TransactionHash=0x0000000000000000...

🔵 Explore your data in the playground:

Visit the playground and run the following query in Examples section.


Examples

Get all entity types total count

query {
  sql(
    query: """
    SELECT
        *
    FROM
        entities
    WHERE
        namespace = 'boilerplate-dev'
    """
  ) {
    stats {
      elapsedMs
    }
    rows
  }
}

Next Steps

The current flow covers a very basic indexing use-case. For more advanced ones, check out the flair-sdk/examples repository.

FAQ

Q: How do I enable/disable real-time ingestion for indexer?
A: For each indexer defined in config.json, you can enable/disable it via the enabled: true/false flag. Remember to run pnpm generate-and-deploy for the changes to apply on the cluster.

Q: How do I configure MongoDB?
A: Run the below command in terminal:

pnpm flair secret set -n mongodb.uri -v mongodb+srv://USERNAME:PASSWORD@HOST:PORT/DB_NAME

You can also manually define the schema under src/schemas or by running the below command:

pnpm flair util infer-schema