Making the world’s decentralised
data more accessible.
SubQuery 201 Workshop - Intermediate
1
2
Agenda
● Introduction
● Basic concepts (manifest file, schema, mappings)
● Build another simple project
● SubQuery Projects
● Summary
● Q&A
Problems
Query Speed
Parachain Diversity
It can take days to query simple chain data from Polkadot
Today, each parachain requires its own indexing and data service
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
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
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?
Node.js (NPM)
npm install -g @subql/cli
Yarn (optional)
Docker
What is needed?
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
Basic
Concepts Summary
SubQuery Network
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
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
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
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
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
Mapping filters
● Use to decide what block, event,
or extrinsic will trigger a mapping
handler.
● Are optional but recommended.
● Will improve indexing
performance.
Custom chains
● SubQuery works with any Substrate based chain!
● Just import your custom types in the project.yaml file and
adjust the mapping functions.
Let’s build a
project together!
SubQuery Network
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!
SubQuery
Projects
SubQuery Network
SubQuery Projects
https://project.subquery.network/
https://doc.subquery.network/publish
/publish.html
● Production grade infrastructure
is provided
● Scaleable, reliable, high
performing
● Free to host
Summary
SubQuery Network
Summary
● Index, transform, and query Substrate chain data
● Manifest, Graphql schema, mappings file
● Hands on exercise
● SubQuery Projects
Follow us on
Telegram | Twitter | Linkedin | Medium | GitHub |
Matrix: #subquery:matrix.org
Website
www.subquery.network
Find Out More

Encode Club workshop slides

  • 1.
    Making the world’sdecentralised data more accessible. SubQuery 201 Workshop - Intermediate 1
  • 2.
    2 Agenda ● Introduction ● Basicconcepts (manifest file, schema, mappings) ● Build another simple project ● SubQuery Projects ● Summary ● Q&A
  • 3.
    Problems Query Speed Parachain Diversity Itcan take days to query simple chain data from Polkadot Today, each parachain requires its own indexing and data service
  • 4.
    Problem: Query Speed Inorder 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 ParachainDiversity 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 anopen 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?
  • 7.
    Node.js (NPM) npm install-g @subql/cli Yarn (optional) Docker What is needed?
  • 8.
    SubQuery Components Extract Filter andextract 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
  • 9.
  • 10.
    The SubQuery Projectin 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 arethree 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 configurationfile 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 ● Thisfile 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 howthe chain data is transformed into the optimised GraphQL entities ● Sit in src/mappings directory ● Referenced in project.yaml under mapping handlers
  • 15.
    Mapping filters ● Useto decide what block, event, or extrinsic will trigger a mapping handler. ● Are optional but recommended. ● Will improve indexing performance.
  • 16.
    Custom chains ● SubQueryworks with any Substrate based chain! ● Just import your custom types in the project.yaml file and adjust the mapping functions.
  • 17.
    Let’s build a projecttogether! SubQuery Network
  • 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!
  • 19.
  • 20.
    SubQuery Projects https://project.subquery.network/ https://doc.subquery.network/publish /publish.html ● Productiongrade infrastructure is provided ● Scaleable, reliable, high performing ● Free to host
  • 21.
  • 22.
    Summary ● Index, transform,and query Substrate chain data ● Manifest, Graphql schema, mappings file ● Hands on exercise ● SubQuery Projects
  • 23.
    Follow us on Telegram| Twitter | Linkedin | Medium | GitHub | Matrix: #subquery:matrix.org Website www.subquery.network Find Out More