๐ ๏ธ Subgraph Development: Build Custom Indexers
Learn how to create, deploy, and maintain subgraphs
Query blockchain data efficiently with The Graph
Your Progress
0 / 5 completed๐ ๏ธ Building Your First Subgraph
A subgraph is your indexing specification. You define: (1) Schemaโwhat data to store, (2) Manifestโwhich contracts/events to watch, (3) Mappingsโhow to transform events into entities. Deploy to The Graph, indexers process your subgraph, and you get a GraphQL endpoint. It's like writing a database migration + ETL pipeline, but for blockchain data. We'll build a subgraph for an ERC-20 token to track all transfers.
๐ฎ Interactive: 4-Step Subgraph Builder
Walk through the subgraph development process. Click through each step to see the code, explanation, and how pieces fit together.
1. Define Schema (schema.graphql)
Step 1 of 4Define entities (data models) that will be stored and queryable
type Token @entity {
id: ID!
address: Bytes!
name: String!
symbol: String!
decimals: Int!
totalSupply: BigInt!
}
type Transfer @entity {
id: ID!
token: Token!
from: Bytes!
to: Bytes!
amount: BigInt!
timestamp: BigInt!
blockNumber: BigInt!
}@entity = stored in database. ID! = required unique identifier. Relationships: Transfer.token links to Token entity. Types map to GraphQL types (String, Int, BigInt, Bytes).
๐ Key Concepts
@derivedFrom for reverse relationships. E.g., Token has transfers: [Transfer!] @derivedFrom(field: "token").