Vana Subgraph
Vana provides a subgraph that indexes the core Vana contract set, useful for querying historic and current data. Below we link to the complete schema as well as provide sample queries to get you started.
Schema
The complete schema can be found at Vana subgraph schema.
It is worth checking this file before creating new queries since the schema is still under development and may change over time.
You can find the endpoint for the Vana subgraphs at the following URLs
Provider | Network | URL |
---|---|---|
GoldSky | Moksha | https://api.goldsky.com/api/public/project_cm168cz887zva010j39il7a6p/subgraphs/moksha/prod/gn |
GoldSky | Vana | https://api.goldsky.com/api/public/project_cm168cz887zva010j39il7a6p/subgraphs/vana/prod/gn |
TheGraph | Moksha | Coming soon |
TheGraph | Vana | Coming soon |
GraphQL queries
Once deployed (whether on The Graph, Goldsky, or locally), your subgraph exposes a GraphQL endpoint. For example:
query {
exampleEntities(first: 5, orderBy: value, orderDirection: desc) {
id
user
value
timestamp
}
}
Filter and Sorting
Your queries can filter by entity fields and sort results. For instance:
{
exampleEntities(where: { user: "0xabcdef1234..." }, orderBy: timestamp, orderDirection: desc) {
...
}
}
Paginating Results
Use first and skip arguments to paginate. E.g.,:
{
exampleEntities(first: 100, skip: 200) {
...
}
}
Time travel queries
When running queries you can specify a particular block number, useful for seeing the state of entities in the past or for seeing how a state changes over time, useful for creating charts . E.g.,:
query {
exampleEntities(
first: 5
block: { number: 1234567 }
orderBy: value
orderDirection: desc
) {
id
value
timestamp
}
}
Sample queries
1. Query for Users
Each user making a stake has a User record created, including nested stakes and file contributions.
{
users(first: 10) {
id
stakes {
id
amount
}
transactions {
id
hash
}
}
}
2. Query a specific DLP and associated totals
The following simple query retrieves the record for the Dlp with an Id of 6, along with the nested totals entity associated to that Dlp.
{
dlp(id:"6") {
id
name
amountStaked
totals {
id
totalVanaStaked
}
}
}
3. Query for EPOCH 2
Each Epoch is represented as an epoch entity. The following sample query retrieves data in epoch 2.
query GetEpochs {
epoch(id: "2") {
id
reward
startBlock
endBlock
}
}
4. Query stakes for a specific Dlp
Where clauses allow for queries to filter results, in this case filtering by dlp, where the stake is still open and hasn't been withdrawn and has an associated user. Elements such as user_not: null are not necessary since every stake has a user but it serves here to demonstrate how a filter can be built up.
{
stakes(
first: 1000
where: {
dlp_: { id: "9" },
closedAt: null,
withdrawnAt: null,
user_not: null
}
orderBy: id
orderDirection: asc
) {
id
amount
user { id }
dlp { id }
}
}
5. Query stake totals for a particular dlp at a block time
In this sample query, we specify a block number which creates a time travel query, running the query at that block point. This is a powerful feature of subgraph since it allows results to be checked in the past or across a timespan, useful for creating charts for example.
query GetDlpTotalStaked {
dlp(block: { number: 1316891 }, id: 6) {
id
amountStaked
totals {
totalVanaStaked
}
}
}
Updated 3 days ago