Skip to content

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:

  1. 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.

  2. Navigate into the root directory of your Squid project and install dependencies by running

    npm ci
    
  3. Modify the src/processor.ts file to set the data source to the RPC URL of your Tanssi appchain. Remove the archive: 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 data

    const processor = new EvmBatchProcessor();
    processor.setDataSource({
      chain: 'INSERT_RPC_URL',
    })
    
  4. Launch Postgres by running

    sqd up
    
  5. Inspect and run the processor

    sqd process
    
  6. Open a separate terminal window in the same directory, then start the GraphQL server

    sqd serve
    
  7. 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:

  1. 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:

  2. Navigate into the root directory of your Squid project and install dependencies by running

    npm ci
    
  3. Modify the src/processor.ts file to set the data source to the RPC URL of your Tanssi appchain. Remove the archive: 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 data

    const 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
    
  4. Launch Postgres by running

    sqd up
    
  5. Inspect and run the processor

    sqd process
    
  6. Open a separate terminal window in the same directory, then start the GraphQL server

    sqd serve
    
  7. 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!

The information presented herein has been provided by third parties and is made available solely for general information purposes. Tanssi does not endorse any project listed and described on the Tanssi Doc Website (https://docs.tanssi.network/). Tanssi Foundation does not warrant the accuracy, completeness or usefulness of this information. Any reliance you place on such information is strictly at your own risk. Tanssi Foundation disclaims all liability and responsibility arising from any reliance placed on this information by you or by anyone who may be informed of any of its contents. All statements and/or opinions expressed in these materials are solely the responsibility of the person or entity providing those materials and do not necessarily represent the opinion of Tanssi Foundation. The information should not be construed as professional or financial advice of any kind. Advice from a suitably qualified professional should always be sought in relation to any particular matter or circumstance. The information herein may link to or integrate with other websites operated or content provided by third parties, and such other websites may link to this website. Tanssi Foundation has no control over any such other websites or their content and will have no liability arising out of or related to such websites or their content. The existence of any such link does not constitute an endorsement of such websites, the content of the websites, or the operators of the websites. These links are being provided to you only as a convenience and you release and hold Tanssi Foundation harmless from any and all liability arising from your use of this information or the information provided by any third-party website or service.
Last update: March 21, 2024
| Created: March 11, 2024