ADVANCED
SUBGRAPH GENERATION
Automatically generate The Graph subgraph scaffolding from your contract.
WHAT IS A SUBGRAPH
A subgraph indexes blockchain events and provides a GraphQL API for querying on-chain data efficiently. This is essential for building performant dApp frontends.
Query historical events without scanning the entire blockchain
Build complex queries with filters, sorting, and pagination
Real-time updates through subscriptions
GENERATED FILES
After deployment, the Subgraph tab becomes available with these files:
schema.graphql
GraphQL schema with entities for each contract event.
subgraph.yaml
Manifest file defining data sources and event handlers.
src/mapping.ts
AssemblyScript handlers for processing events.
package.json
Dependencies and deployment scripts.
DEPLOYING THE SUBGRAPH
- 1
Export the Files
Copy files from the Subgraph tab or export the full project.
- 2
Install Dependencies
npm install - 3
Generate Types
npm run codegen - 4
Build
npm run build - 5
Deploy to The Graph Studio
graph auth --studio YOUR_KEYnpm run deploy