Key Advantages of SubQuery
SubQuery offers several competitive advantages that make it ideal for building Neutron indexers:- Multi-chain Aggregation: SubQuery can aggregate data not only within a chain but across multiple blockchains all within a single project. This allows the creation of feature-rich dashboard analytics, multi-chain block scanners, or projects that index IBC transactions across zones.
-
Superior Performance: SubQuery delivers high performance through:
- Multiple RPC endpoint configurations
- Multi-worker capabilities
- Configurable caching architecture
- GraphQL API: SubQuery automatically generates a GraphQL API for your indexed data, making it easy to query exactly what you need.
- Developer Experience: SubQuery provides a seamless developer experience with detailed documentation, examples, and tooling.
Getting Started with SubQuery for Neutron
Prerequisites
Before starting, make sure you have:- Node.js (v14 or later)
- NPM or Yarn
- Docker (for local development)
- Basic JavaScript/TypeScript knowledge
Step 1: Install the SubQuery CLI
Step 2: Initialize a New Project
You can start with the Neutron starter project:Step 3: Understanding the Project Structure
A SubQuery project contains several important files:- project.ts: The main configuration file that defines your project, data sources, and network settings
- schema.graphql: Defines the GraphQL schema for your indexed data
- src/mappings/: Contains the handler functions that process blockchain data
Step 4: Configure Your Project
Edit theproject.ts
file to configure your Neutron data sources. Here’s an example configuration for indexing Neutron data:
Step 5: Define Your Data Schema
Edit theschema.graphql
file to define the structure of your indexed data. Here’s an example for tracking transfers:
Step 6: Implement Your Mapping Functions
Create handler functions in thesrc/mappings/
directory to process blockchain data and store it according to your schema:
Step 7: Build and Run Your Project
Build and run your SubQuery project locally:Step 8: Query Your Indexed Data
Once the indexer is running, you can access the GraphQL playground athttp://localhost:3000/graphql
to query your indexed data:
Hosting Your SubQuery Project
SubQuery is open-source, meaning you have the freedom to run it in several ways:- Locally: Run on your own computer or cloud provider by following the instructions for running SubQuery locally.
- SubQuery Managed Service: Publish to SubQuery’s enterprise-level Managed Service, which hosts your SubQuery project in production-ready services with zero-downtime blue/green deployments. There’s even a generous free tier. Learn how to publish your project.
- SubQuery Network: Publish to the decentralized SubQuery Network, which indexes and serves data to the global community in an incentivized and verifiable way. The SubQuery Network supports Neutron from launch.
Indexing Neutron-Specific Data
When indexing Neutron data, you might be interested in specific modules and their events:Interchain Queries (ICQ)
To index ICQ-related events, add specific event handlers:Smart Contract Events
To index events emitted by smart contracts:Additional Resources
Remember that indexers need to be kept in sync with the blockchain they’re indexing. Make sure to implement proper error handling and recovery mechanisms for your production indexers.