- Clone the repository
git clone https://github.com/plumenetwork/subgraph-template.git
cd subgraph-template
- Install dependencies
npm install @graphprotocol/graph-ts
- Add your contract abi to
/abi
- Add the deployed contract address to your config
plume.json
file - Customize mapping.ts and schema.graphql
mapping.ts
: This TypeScript file contains the logic to process blockchain events and map them to entities in your GraphQL schema, enabling the indexing of blockchain data for queries.schema.graphql
: Defines the structure of data to be indexed from the blockchain, detailing entities, their fields, and relationships for efficient querying through your subgraph.
Ref : The Graph for more details
- Generate AssemblyScript types for smart contract ABIs and the GraphQL schema, facilitating type-safe development of the subgraph.
graph codegen
- Compile the subgraph to WebAssembly
graph build
- Deploy subgraph to goldksy
goldsky subgraph deploy nft/1.0.0 --path .
- Go the the GraphQl api that you get after running the above command
Here are some sample queries for the template which can query all holders of a NFT collection
- Fetch All Accounts With Their Tokens
accounts {
id
tokensOwned
tokens {
id
transferCount
}
}
}
Output
"data": {
"accounts": [
{
"id": "0x372532360b38d56f41b4863fcf4ded163326e70b",
"tokensOwned": "2",
"tokens": [
{
"id": "1",
"transferCount": "1"
},
{
"id": "2",
"transferCount": "1"
}
]
}
]
}
}
- Fetch All Accounts and Their Token Count
accounts {
id
tokensOwned
}
}
Output
"data": {
"accounts": [
{
"id": "0x372532360b38d56f41b4863fcf4ded163326e70b",
"tokensOwned": "2"
}
]
}
}