4. Problem: Query Speed
In order to build increasingly complex and intuitive
applications, developers need powerful tools to
process and query their data faster.
It can take days to query simple chain data from Polkadot
5. Problem: Polkadot Parachain Diversity
darwinia.js
DAPP
SDK
PROTOCOL
polkadot.js acala.js
What does Alice have in her wallet?
Scenario: account balance across chains
200 RING on
Darwinia
100 DOT on
Polkadot
50 ACA on
Acala
Too many protocols / smart contract engine etc
Current flow
Today, each parachain requires its own indexing and data service
6. SubQuery is an open source project that allows developers to index, transform,
and query Substrate chain data to power their applications.
Think of it like the Google for blockchain
What is SubQuery?
8. SubQuery Components
Extract
Filter and extract
real time chain data
3
1 2
Transform
Transform and aggregate
chain data to your need
Persist
Save data to high
performance database
Query
Quickly query your dataset using complex
GraphQL syntax in your dApps
4
Web Apps Webhooks
(e.g.IFTTT)
Data for other
Blockchains
Mobile
Apps
10. The SubQuery Project in a Nutshell
A SubQuery project is a set of instructions on how to index data.
It has the following three main parts
● GraphQL Schema File - the shape of
your data
● Manifest File - the configuration
● Mapping Files - data transformation
pipelines
11. Handler Types
There are three mapping types:
Event:
balances.deposit
Event:
balances.deposit
Call:
timestamp.set
Call:
timestamp.set
● Block Handler - each and every block
● Event Handler - each new (filtered) event
● Call Handler - each new (filtered) call
Event:
balances.deposit
12. Manifest file
A configuration file that:
● Defines the details of how
SubQuery will index and
transform the chain data.
● project.yaml
https://doc.subquery.network/create/manifest.html
13. GraphQL Schema
● This file dictates the shape of your data from SubQuery
● schema.graphql
● Any changes to this file requires a “regeneration” via yarn codegen or
npm run-script codegen
14. Mappings
● Defines how the chain data
is transformed into the
optimised GraphQL entities
● Sit in src/mappings
directory
● Referenced in project.yaml
under mapping handlers
15. Mapping filters
● Use to decide what block, event,
or extrinsic will trigger a mapping
handler.
● Are optional but recommended.
● Will improve indexing
performance.
16. Custom chains
● SubQuery works with any Substrate based chain!
● Just import your custom types in the project.yaml file and
adjust the mapping functions.
18. Hands on exercise
● SubQuery Transfers
● Define the shape of our data (schema.graphql)
● Update the our handlers in the manifest file (project.yaml)
● Update the mappings file (mappingHandlers.ts)
Open the SubQuery 201 Lab Workbook and follow along!