- Fetch all historical USDC transfers on Ethereum from the SQD Network
- Decode it
- Save it to a local Postgres database
- Start a GraphQL server with a rich API to query the historical USDC transfers.
Prerequisites
- (On Windows) WSL
- Node.js v18+
- Git
- Docker (for running Postgres)
Step 1
Install Squid CLI:Squid CLI is a multi-purpose utility tool for scaffolding and managing the indexers, both locally and in SQD Cloud.
Step 2
Scaffold the indexer project (squid) from an example repo using Squid CLI:The example is just a public GitHub repo with a squid project pre-configured to index USDC.
Step 3
Inspect the Here,The rest of the file is about data processing and storage:
./src folder:src
abi
usdc.ts
main.ts
model
generated
index.ts
marshal.ts
usdcTransfer.model.ts
index.ts
src/abi/usdcis a utility module generated from the JSON ABI of the USDC contract. It contains methods for event decoding, direct RPC queries and some useful constants.src/modelcontains TypeORM model classes autogenerated fromschema.graphql. Squids use them to populate Postgres.
main.ts is the main executable. In this example, it also contains all the data retrieval configuration:Step 5
The processor is a background process that continously fetches the data, decodes it and stores it in a local Postgres. All the logic is defined in Processor will connect to Postgres using the connection parameters from then start the processor withThe indexer is now running.
main.ts and is fully customizable.To run the processor, we first start a local Postgres where the decoded data is persisted (the template comes with a Docker compose file):.env.Apply database migrations withStep 6
Start the GraphQL API serving the transfers data from Postgres:The server comes with a GraphQL playground available at
localhost:4350/graphql.