Quickstart: EVM chains
The evm
squid template indexes transactions to the "black hole" address 0x0000000000000000000000000000000000000000
, persists their data into a Postgres database and serves it over a GraphQL API. It is intended to be a starter project for building custom squids indexing data from Ethereum and other EVM chains.
Pre-requisites
- Node v16.x or newer
- Squid CLI
- Docker
With the exception of sqd init
, sqd
commands mentioned here are just scripts defined in commands.json
that the sqd
executable automatically discovers. Take a look at the contents of this file to learn more about how squids work under the hood.
Please note:
- The squid template is not compatible with
yarn
and expects anpm
-generatedpackage-lock.json
file in the root.
Step 1: Scaffold from a template
Come up with a new memorable name for your squid and scaffold from squid-evm-template
using sqd init
:
sqd init my-awesome-squid --template evm
cd my-awesome-squid
Explore all available templates with sqd init --help
. You may choose the gravatar
template as a starting point for indexing EVM smart contracts as well.
Step 2: Install dependencies
npm ci
Step 3: Set the network
Inspect src/processor.ts
and set the EVM network of interest. Consult the supported networks and processor configuration pages.
Step 4: Launch Postgres and detach
sqd up
Step 5: Inspect and run the processor
The squid fetches, aggregates and persists burn transactions in the processor.run()
method. The Burn
entity is defined in schema.graphql
, and the TypeORM model class used by this template was generated with sqd codegen
. You can learn more about this in the squid development section.
Let's run the processor:
sqd process
It outputs simple aggregations of the burned ETH and batch-inserts the tx data into the Postgres database.
Step 6: Start the GraphQL server
Run the API server in a separate terminal window, then visit the GraphiQL console:
sqd serve
The console auto-serves the Burn
entity data we are uploading to Postgres. For example, one can explore the top-10 historical burns:
query MyQuery {
burns(orderBy: value_DESC) {
address
block
id
txHash
value
}
}
Step 7: Customize
Hack the schema file schema.graphql
and the processor src/processor.ts
to index the data your way!
What's next?
- Migrate your existing subgraphs to Subsquid
- Define your own data schema
- Explore examples of squids for EVM networks, from simple transfer indexing to DEX analytics
- Dive deeper into
EvmBatchProcessor
- Explore how to enhance the GraphQL API with custom SQL, caching and limits
- Deploy the squid to the Aquarium hosted service