Subgraph
Query plans, subscriptions, and charges using The Graph.
Overview
The Cron Protocol subgraph indexes all on-chain events into a GraphQL API. Use it to query historical data, build analytics dashboards, or power your frontend without RPC calls.
Entities
| Entity | Description |
|---|---|
Plan | Subscription plan with metadata, stats, and subscriber list |
Subscription | Individual subscriber record with status and charge history |
Charge | Each successful charge event with amounts and keeper info |
ProtocolStats | Global aggregate — total plans, subscriptions, volume |
DailySnapshot | Daily activity snapshots for analytics |
Example queries
Get all plans for a merchant
graphql
query MerchantPlans($merchant: Bytes!) {
plans(where: { merchant: $merchant }, orderBy: createdAt, orderDirection: desc) {
id
token
amount
interval
active
activeSubscribers
totalChargeVolume
createdAt
}
}Get subscribers for a plan
graphql
query PlanSubscribers($planId: ID!) {
plan(id: $planId) {
subscriptions(first: 50, orderBy: startedAt) {
subscriber
status
startedAt
lastChargedAt
chargeCount
}
}
}Recent charges
graphql
query RecentCharges($planId: BigInt!) {
charges(
where: { planId: $planId }
first: 25
orderBy: blockTimestamp
orderDirection: desc
) {
subscriber
amount
keeper
keeperBounty
blockTimestamp
txHash
}
}Protocol-wide stats
graphql
query ProtocolStats {
protocolStats(id: "GLOBAL") {
totalPlans
totalSubscriptions
activeSubscriptions
totalChargeVolume
totalCharges
totalKeepers
}
}Calling from TypeScript
typescript
const SUBGRAPH_URL = process.env.NEXT_PUBLIC_SUBGRAPH_URL;
async function querySubgraph<T>(query: string, variables?: Record<string, unknown>): Promise<T> {
const res = await fetch(SUBGRAPH_URL, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ query, variables }),
});
const json = await res.json();
return json.data as T;
}Deployment
See Subgraph Deploy for instructions on deploying the subgraph to The Graph Studio.
[i] Dashboard integration
The dashboard uses
NEXT_PUBLIC_SUBGRAPH_URL to query the subgraph. Set this env var in Vercel to point to your deployed subgraph endpoint.