- Node.js and npm/yarn installed
- Graph CLI installed (
npm install -g @graphprotocol/graph-cli) - Access to a Graph account (for hosted service) or a Graph Node (for local deployment)
- Clone and Install Dependencies
git clone https://github.com/galxe/vanilla-subgraph.git
cd vanilla-subgraph
yarn install- Generate Types
graph codegen- Build the Subgraph
graph build- Deploy the Subgraph
For hosted service:
# Authenticate (do this once)
graph auth --product hosted-service <YOUR_ACCESS_TOKEN>
# Deploy
graph deploy After deployment, you can query the subgraph using GraphQL. Here are some example queries:
- Get Contract Global Statistics
{
contractStats(id: "0x994b9a6c85e89c42ea7cc14d42afdf2ea68b72f1") {
totalAddresses # Total number of unique addresses
totalTxCount # Total number of transactions
totalVolume # Total transaction volume
updatedAt # Last update timestamp
}
}- Get Daily Address Statistics
# Get statistics for a specific address
{
dailyAddressStats(
where: {
contract: "0x994b9a6c85e89c42ea7cc14d42afdf2ea68b72f1",
address: "0x..."
}
orderBy: date
orderDirection: desc
first: 30
) {
date
txCount # Daily transaction count
volume # Daily transaction volume
}
}
# Get top addresses by volume for a specific day
{
dailyAddressStats(
where: {
contract: "0x994b9a6c85e89c42ea7cc14d42afdf2ea68b72f1",
date: 20240301
}
orderBy: volume
orderDirection: desc
first: 10
) {
address
txCount
volume
}
}
# Get top addresses by transaction count for a specific day
{
dailyAddressStats(
where: {
contract: "0x994b9a6c85e89c42ea7cc14d42afdf2ea68b72f1",
date: 20240301
}
orderBy: txCount
orderDirection: desc
first: 10
) {
address
txCount
volume
}
}-
ContractStats (Global Statistics)
id: Contract addresstotalAddresses: Total number of unique addressestotalTxCount: Total number of transactionstotalVolume: Total transaction volumeupdatedAt: Last update timestamp
-
DailyAddressStats (Daily Address Statistics)
id: Format: "{contract}-{address}-{yyyyMMdd}"contract: Contract addressaddress: User addressdate: Date (YYYYMMDD)txCount: Daily transaction countvolume: Daily transaction volume
-
AddressTracker (Address Tracking)
id: Format: "{contract}-{address}"contract: Contract addressaddress: User address
The subgraph tracks the following events:
BuyTicket: When a user buys a ticketCancelTicket: When a user cancels a ticketCreateOrder: When a user creates an orderDepositFund: When a user deposits fundsWithdrawFund: When a user withdraws fundsSettleOrder: When an order is settled
- Make changes to the schema, mappings, or configuration
- Regenerate types with
graph codegen - Build the updated subgraph with
graph build - Deploy the new version with
graph deploy