subgraph-development-guide
БесплатноБез исполняемых скриптовНе проверенGuide to building blockchain data indexes with The Graph — subgraph architecture, schema design, mapping handlers, deployment, and querying. Covers GraphQL…
от nirholas★ 289 звёзд на GitHubОб этом скилле
Subgraph Development Guide
The Graph is the indexing protocol for blockchain data. Subgraphs turn raw blockchain events into queryable GraphQL APIs. This guide covers how they work and how to build them.
Why Subgraphs?
The Problem
Reading blockchain data directly is painful:
- RPC calls are slow and sequential
- No aggregation (can't query "total volume last 7 days")
- No relationships (can't join swaps with token metadata)
- Rate limits on public RPCs
The Solution
Subgraphs listen to blockchain events, process them, and store structured data:
Blockchain Events → Subgraph Indexer → GraphQL API
(Swap, Transfer, (Processes, (Fast queries,
Mint, Burn) aggregates) relationships)
Architecture
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ 1. Schema │ │ 2. Mappings │ │ 3. Manifest │
│ (GraphQL types) │ │ (Event handlers)│ │ (subgraph.yaml) │
│ │ │ │ │ │
│ type Token { │ │ handleSwap(e) { │ │ dataSources: │
│ id: ID! │ │ // process │ │ - name: Pool │
│ symbol: String│ │ // and save │ │ source: │
│ volume: BigInt│ │ } │ │ abi: Pool │
│ } │ │ │ │ address: │
└─────────────────┘ └─────────────────┘ └─────────────────┘
Three Core Files
| File | Purpose |
|---|---|
schema.graphql |
Define your data model (entities) |
src/mapping.ts |
Event handler functions (AssemblyScript) |
subgraph.yaml |
Manifest — which contracts, events, and chains to index |
Building a Token Transfer Tracker
Step 1: Schema (schema.graphql)
type Token @entity {
id: ID! # Contract address
symbol: String!
name: String!
decimals: Int!
totalSupply: BigInt!
transferCount: BigInt!
holderCount: BigInt!
}
type Transfer @entity {
id: ID! # tx hash + log index
token: Token!
from: Bytes!
to: Bytes!
value: BigDecimal!
timestamp: BigInt!
blockNumber: BigInt!
}
type Account @entity {
id: ID! # Wallet address
balances: [AccountBalance!]! @derivedFrom(field: "account")
}
type AccountBalance @entity {
id: ID! # account-token
account: Account!
token: Token!
balance: BigDecimal!
}
Step 2: Manifest (subgraph.yaml)
specVersion: 0.0.5
schema:
file: ./schema.graphql
dataSources:
- kind: ethereum
name: USDC
network: arbitrum-one
source:
address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831"
abi: ERC20
startBlock: 100000000
mapping:
kind: ethereum/events
apiVersion: 0.0.7
language: wasm/assemblyscript
entities:
- Token
- Transfer
- Account
abis:
- name: ERC20
file: ./abis/ERC20.json
eventHandlers:
- event: Transfer(indexed address,indexed address,uint256)
handler: handleTransfer
file: ./src/mapping.ts
Step 3: Mapping (src/mapping.ts)
import { Transfer as TransferEvent } from "../generated/USDC/ERC20"
import { Token, Transfer, Account, AccountBalance } from "../generated/schema"
import { BigInt, BigDecimal } from "@graphprotocol/graph-ts"
export function handleTransfer(event: TransferEvent): void {
// Load or create token
let token = Token.load(event.address.toHexString())
if (token == null) {
token = new Token(event.address.toHexString())
token.symbol = "USDC"
token.name = "USD Coin"
token.decimals = 6
token.totalSupply = BigInt.fromI32(0)
token.transferCount = BigInt.fromI32(0)
token.holderCount = BigInt.fromI32(0)
}
token.transferCount = token.transferCount.plus(BigInt.fromI32(1))
token.save()
// Create transfer entity
let transfer = new Transfer(
event.transaction.hash.toHexString() + "-" + event.logIndex.toString()
)
transfer.token = token.id
transfer.from = event.params.from
transfer.to = event.params.to
transfer.value = event.params.value.toBigDecimal().div(
BigDecimal.fromString("1000000") // 6 decimals
)
transfer.timestamp = event.block.timestamp
transfer.blockNumber = event.block.number
transfer.save()
}
Querying Subgraphs
GraphQL Query Examples
Top tokens by transfer volume:
{
tokens(first: 10, orderBy: transferCount, orderDirection: desc) {
id
symbol
transferCount
}
}
Recent large transfers:
{
transfers(
first: 20
orderBy: timestamp
orderDirection: desc
where: { value_gt: "100000" }
) {
from
to
value
timestamp
token { symbol }
}
}
Account balances:
{
account(id: "0x1234...") {
balances {
token { symbol }
balance
}
}
}
Query Endpoints
| Network | Hosted Service |
Установить subgraph-development-guide в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл subgraph-development-guide?
Guide to building blockchain data indexes with The Graph — subgraph architecture, schema design, mapping handlers, deployment, and querying. Covers GraphQL APIs for DEX data, token transfers, and DeFi protocol events. Use when explaining blockchain indexing or building custom data pipelines.
Как установить скилл subgraph-development-guide?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл subgraph-development-guide запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic