Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building Powerful EVM Indexers with SubQuery: U...

Building Powerful EVM Indexers with SubQuery: Unlocking Web3 Data at Scale

In the expanding Web3 ecosystem, efficient access to on-chain data is critical for building responsive dApps and analytics platforms. This talk introduces attendees to the world of blockchain indexing by walking through the process of building a performant EVM-compatible indexer using SubQuery. We'll explore how SubQuery's indexing framework simplifies complex data extraction, supports Ethereum and other EVM chains, and enables real-time querying for smart contract events, transactions, and user-centric data. Whether you're building DeFi dashboards, NFT explorers, or governance tools, this session will give you the skills and clarity needed to start shipping data-driven dApps confidently.

Avatar for Desmond Obisi

Desmond Obisi

July 05, 2025
Tweet

More Decks by Desmond Obisi

Other Decks in Technology

Transcript

  1. July 2025 Developer Meetup With Mantle Building Powerful EVM Indexers

    with SubQuery: Unlocking Web3 Data at Scale!
  2. Table of Contents 1 Why Blockchain Indexing Matters 2 SubQuery

    vs The Graph 3 SubQuery Architecture 4 Mantle Quickstart: GraphQL Schema 5 Mantle Quickstart: Manifest Configuration 6 Mantle Quickstart: Mapping Functions 7 Mantle Quickstart: Build, Run, Query 8 Deployment, Use Cases, Best Practices
  3. Welcome to Dev Meetup With Mantle! What you will learn:

    1. What blockchain indexing is and why it’s important in Web3 2. How SubQuery compares to other indexers like The Graph 3. How to setup and configure an indexer for any EVM-based chain(Mantle) 4. How to extract and transform smart contract data into queryable APIs using GraphQL 5. Real-world examples and use cases across DeFi, NFTs, and analytics
  4. Why Blockchain Indexing Matters 1. Data Access: Blockchains store vast

    raw data (transaction logs, blocks, state) that is not easily searchable. Indexers organize this data into structured databases, making it “easily accessible and searchable” 2. Real-Time Queries: Decentralized apps (DeFi platforms, NFT marketplaces, analytics tools) require up-to-date data (balances, events, history). Indexing enables fast retrieval via GraphQL, improving performance and user experience. 3. Use Cases: For example, trading bots and wallets need instant access to transaction history and portfolio data. Without indexing, queries would be slow or impractical. Indexers extract data (from full nodes) and build query APIs to address this gap.
  5. SubQuery vs The Graph 1. Performance: SubQuery’s multi-threaded indexer can

    be significantly faster than The Graph. Benchmarks show ~1.8–3.9× speedup on common projects. Faster indexing means quicker development cycles. 2. Flexibility: SubQuery mappings use TypeScript, allowing any JS library or external API call. Unlike The Graph’s sandbox, SubQuery can import custom logic (e.g. fetch CoinGecko prices during indexing) 3. Chain Support: SubQuery supports 300+ chains, including all EVMs and many non-EVM chains (Polkadot, Cosmos, Solana, etc.). This unified SDK means one tool for multi-chain data. 4. Ecosystem: Both use GraphQL APIs, so devs can re-use queries. SubQuery offers more control (rich CLI options) and a decentralized network (indexer staking) without excluding smaller chains. 5. Cost: SubQuery’s planned network is more accessible (lower stake) and costs less per query than locking up large GRT amounts.
  6. SubQuery Architecture SubQuery projects have a standardized scaffold. Key files

    include: project.ts (manifest/config), schema.graphql (entity definitions), an abis/ folder, and src/mappings/ for handler code. The manifest lists data sources (chain, startBlock, contract address, ABI) and mapping handlers (Block/Transaction/Log). Since Mantle is EVM-compatible, we use Ethereum tooling (@subql/node-ethereum, ethereum/Runtime, etc.) in the project. 1. Multi-Chain: The same project can index multiple chains by adding data sources – no separate infrastructure needed. 2. Lightweight: You can use public RPC endpoints (no need to run a full archive node), making development simpler.
  7. SubQuery Architecture Contd. Directory snapshot: ├─ abis/erc20.abi.json ├─ project.yaml #

    Datasource: EVM Runtime, Mantle, startBlock 1 ├─ schema.graphql # Transfer & Approval entities ├─ src/mappings.ts # handleLog & handleApprove handlers ├─ docker-compose.yml # Local indexer + PostgreSQL + GrapghQL
  8. Mantle Quickstart: GraphQL Schema In schema.graphql we define the entities

    we want to query .These fields map to the on-chain data we’ll extract. SubQuery will generate TypeScript classes (Transfer, Approval) from this schema during codegen. For example, we index ERC‑20 Transfer and Approval events, so we add:
  9. Mantle Quickstart: Manifest Configuration The project.ts manifest connects to the

    Mantle chain and smart contract. We import a standard ERC-20 ABI (erc20.abi.json) and specify the Mantle native token’s contract address (e.g. 0×DeadDeAd...0000). We then configure handlers: e.g., an Ethereum TransactionHandler for the approve function (calls) and an EventHandler for the Transfer event. For example: 1. EthereumHandlerKind.Call – calls handleTransaction when approve(spender, amount) is invoked. 2. EthereumHandlerKind.Event – calls handleLog on Transfer(address, address, uint256) events. Each handler is linked to the corresponding mapping function we’ll write. Sample of the config file here
  10. Mantle Quickstart: Mapping Functions The src/mappings folder has the handlers.

    For Transfer events (handleLog), the function receives a TransferLog object with fields like args.from, args.to, args.value. We construct a Transfer entity and save it:
  11. Mantle Quickstart: Mapping Functions Contd. For Approval calls (handleTransaction), we

    receive an ApproveTransaction with tx.args[0] (spender) and tx.args[1] (amount). We create and save an Approval entity: These handlers extract on-chain data and populate our indexed entities
  12. Mantle Quickstart: Build, Run, Query 1. Codegen: Run yarn codegen

    to generate TypeScript types for entities and contract interfaces. This creates src/types with classes for Transfer, Approval, and ABI events. 2. Build: Run yarn build to compile and bundle the project (output in /dist) subquery.network. 3. Run (Docker): Start the indexer stack with yarn start:docker (or npm run-script start:docker). This spins up a SubQuery node, Postgres DB, and GraphQL server as per docker-compose.yml. The logs will show blocks being fetched and processed. These steps mirror the standard SubQuery workflow.
  13. Mantle Quickstart: Build, Run, Query Contd. 1. Open a browser

    to http://localhost:3000. You’ll see a GraphQL playground and an automatically generated docs pane. 2. Example query for the first 5 Transfers and Approvals: 3. The response will return indexed data for those entities (e.g., transaction hashes, values). You can tweak filters and fields interactively in the GraphQL IDE.
  14. Deployments, Use Cases, Best Practices 1. Self-Hosted: You can run

    your own SubQuery node (via Docker, Kubernetes, etc.) for full control. This is ideal for private data or custom scaling. The CLI offers tuning (memory, cache) and you manage the database/backup. 2. SubQuery Network (Managed): A decentralized service where indexers run publicly. You deploy your SubQuery project on the network and pay queries in $SQT. The network provides a GraphQL endpoint for your data. SubQuery’s hosted service “will index and persist the chain state, and provide a production GraphQL endpoint that can replace self-hosted implementations”.
  15. Deployment, Use Cases, Best Practices Contd. Use Cases: 1. DeFi

    Dashboards: e.g., Folks Finance uses SubQuery to aggregate multi-chain portfolio/yield data in real time. 2. NFT Marketplaces: e.g., Ambur (Archway) indexes NFT metadata and ownership history for instant browsing. 3. Wallets & Explorers: Nova and Fearless wallets use SubQuery to fetch balances, transfers, and staking activity across networks. 4. Staking: StakeStone uses SubQuery’s indexing to track cross-chain staking balances and rewards. Best Practices: 1. Use filters in handlers to target only needed data (as in the demo, filtering by function/event). 2. Run codegen/build after any schema or ABI change to keep types in sync. 3. Monitor logs and use CLI flags to adjust performance (batch size, parallelism). 4. Test locally with Docker before production deployment.
  16. Thank You For Joining The Session! Resources 1. SubQuery Documentation:

    subquery.network/docs/indexer – official guides (quickstarts, tutorials). 2. GitHub Examples: The Mantle Starter Project (hello world) on GitHub (see SubQuery’s ethereum-subql-starter repo, Mantle). 3. Community & Support: SubQuery Discord for technical help. 4. Video Demo: SubQuery YouTube channel for workshop recordings and tutorials. Questions and Answers