Indexing a Tanssi Appchain with Subsquid¶
Introduction¶
Subsquid is a data network that allows rapid and cost-efficient retrieval of blockchain data from 100+ chains using Subsquid’s decentralized data lake and open-source SDK. In simple terms, Subsquid can be thought of as an ETL (extract, transform, and load) tool with a GraphQL server included. It enables comprehensive filtering, pagination, and even full-text search capabilities. Subsquid has native and full support for both EVM and Substrate data, even within the same project.
This quick-start guide will show you how to create a Subsquid project and configure it to index data on a Tanssi appchain. There is one section catered towards Substrate appchains and another towards EVM appchains. However, if you're building on an EVM appchain, you may also reference the Substrate section, if you also need to index Substrate data.
For a more comprehensive end-to-end tutorial for EVM appchains, be sure to check out the Indexing ERC-20 Transfers on a Tanssi EVM Appchain tutorial.
Checking Prerequisites¶
For the examples in this guide, you will need to have the following:
Index a Tanssi Substrate Appchain¶
To get started indexing Substrate data on your Tanssi appchain, you'll need to create a Subsquid project and configure it for your Tanssi appchain by taking the following steps:
-
Create a Subsquid project based on the Substrate template by running
sqd init INSERT_SQUID_NAME --template substrate
For more information on getting started with this template, please check out the Quickstart: Substrate chains guide on Subsquid's documentation site.
-
Navigate into the root directory of your Squid project and install dependencies by running
npm ci
-
Modify the
src/processor.ts
file to set the data source to the RPC URL of your Tanssi appchain. Remove thearchive: lookupArchive
line as a Squid archive will not be used. Here, you'll need to specify the RPC URL of your Tanssi Substrate appchain, as the endpoint is used to ingest chain dataconst processor = new EvmBatchProcessor(); processor.setDataSource({ chain: 'INSERT_RPC_URL', })
-
Launch Postgres by running
sqd up
-
Inspect and run the processor
sqd process
-
Open a separate terminal window in the same directory, then start the GraphQL server
sqd serve
-
You can query your template Substrate Squid with the below sample query. If you've modified the template Substrate squid to index different data, you'll need to modify this query accordingly
query MyQuery { accountsConnection(orderBy: id_ASC) { totalCount } }
And that's all you have to do to configure your Subsquid project to index Substrate data on your Tanssi Substrate appchain! Now you can update the schema.graphql
, src/main.ts
, typegen.json
, and src/processor.ts
files to index the data you need for your project!
Index a Tanssi EVM Appchain¶
To get started indexing EVM data on a Tanssi EVM appchain, you'll need to create a Subsquid project and configure it for your Tanssi appchain by taking the following steps:
-
You can create a Subsquid project for EVM data by using the generic EVM template or you can use the ABI template for indexing data related to a specific contract
sqd init INSERT_SQUID_NAME --template evm
sqd init INSERT_SQUID_NAME --template abi
For more information on getting started with both of these templates, please check out the following Subsquid docs:
-
Navigate into the root directory of your Squid project and install dependencies by running
npm ci
-
Modify the
src/processor.ts
file to set the data source to the RPC URL of your Tanssi appchain. Remove thearchive: lookupArchive('eth-mainnet')
line as a Squid archive will not be used. Here, the RPC URL of the demo EVM appchain is specified. The Squid project will use the RPC endpoint to ingest the relevant dataconst processor = new EvmBatchProcessor(); processor.setDataSource({ chain: 'INSERT_RPC_URL', })
Note
To try this out on the demo EVM appchain, you can use the following RPC URL:
https://fraa-dancebox-3001-rpc.a.dancebox.tanssi.network
-
Launch Postgres by running
sqd up
-
Inspect and run the processor
sqd process
-
Open a separate terminal window in the same directory, then start the GraphQL server
sqd serve
-
You can now run queries, such as the sample query below, against your Squid on the GraphQL playground at http://localhost:4350/graphql. If you've modified the template Substrate squid to index different data, you'll need to modify this query accordingly
query MyQuery { burns(orderBy: value_DESC) { address block id txHash value } }
And that's all you have to do to configure your Subsquid project to index EVM data on your Tanssi EVM appchain! Now you can update the schema.graphql
, src/main.ts
, and src/processor.ts
files to index the data you need for your project!
If you're interested in a more comprehensive step-by-step tutorial to get started indexing data for your Tanssi appchain, you can check out the Indexing ERC-20 Transfers on a Tanssi EVM Appchain tutorial!
| Created: March 11, 2024