This repository contains boilerplate scripts, abis and schema for indexing (catch all contract events/transactions) and syncing it to your own database.
git clone https://github.com/flair-sdk/starter-boilerplate.git my-indexer
cd my-indexer && pnpm i
or open in gitpod:
pnpm flair auth
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
.
pnpm generate-and-deploy
# 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"
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...
Visit the playground and run the following query in Examples section.
- Method:
POST
- Endpoint: https://api.flair.build/
- Headers:
X-API-KEY: <your-api-key>
- Body:
query {
sql(
query: """
SELECT
*
FROM
entities
WHERE
namespace = 'boilerplate-dev'
"""
) {
stats {
elapsedMs
}
rows
}
}
The current flow covers a very basic indexing use-case. For more advanced ones, check out the flair-sdk/examples repository.
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