Practical Query Samples
Real-world GraphQL query examples for common use cases.
Practical Query Samples
This page provides developers with GraphQL query examples for the Staking Rewards API, demonstrating how to retrieve staking metrics for various blockchain assets.
Refer to the Quick Start Guide for initial setup instructions with JavaScript and Python.
Get Reward Rate for Ethereum
Retrieve the reward_rate metric for Ethereum:
{
assets(where: { symbols: ["ETH"] }, limit: 1) {
name
symbol
slug
logoUrl
metrics(where: { metricKeys: ["reward_rate"] }, limit: 1) {
metricKey
defaultValue
}
}
}Get staked_tokens Metric for Ethereum
Query the staked_tokens metric including change metrics:
{
assets(where: { slugs: ["ethereum-2-0"] }, limit: 1) {
slug
id
metrics(where: { metricKeys: ["staked_tokens"] }, limit: 1) {
metricKey
defaultValue
changeAbsolutes
changePercentages
}
}
}Get staked_tokens of Validators for Cosmos
Filter by asset (Cosmos), type (pos/proof-of-stake), and retrieve validator addresses, statuses, and staked token metrics:
{
rewardOptions(
where: {
inputAsset: { slugs: ["cosmos"] }
typeKeys: ["pos"]
}
limit: 10
offset: 0
) {
providers(limit: 1) {
slug
}
validators(limit: 100) {
address
status {
label
}
metrics(where: { metricKeys: ["staked_tokens"] }, limit: 1) {
metricKey
defaultValue
}
}
}
}Get reward_rate with Providers and Validators
Fetch reward rates from providers and validators, ordered by staked_tokens:
{
rewardOptions(
where: {
inputAsset: { slugs: ["cosmos"] }
typeKeys: ["pos"]
}
order: { metricKey_desc: "staked_tokens" }
limit: 10
offset: 0
) {
providers(limit: 1) {
slug
}
metrics(where: { metricKeys: ["reward_rate"] }, limit: 1) {
metricKey
defaultValue
}
validators(limit: 100, offset: 0) {
address
status {
label
}
metrics(where: { metricKeys: ["reward_rate"] }, limit: 1) {
metricKey
defaultValue
}
}
}
}Get ID for an Asset
Obtain an asset's unique identifier:
{
assets(where: { slugs: ["ethereum-2-0"] }, limit: 1) {
slug
id
}
}Retrieving Historical Metrics
Retrieve three different metrics with date filtering from 2023-01-01 onward:
{
stakingmcap: metrics(
where: {
asset: { id: "ASSET_ID" }
metricKeys: ["staking_marketcap"]
createdAt_gt: "2023-01-01"
}
limit: 3
order: { createdAt: desc }
) {
...histData
}
rewardRate: metrics(
where: {
asset: { id: "ASSET_ID" }
metricKeys: ["reward_rate"]
createdAt_gt: "2023-01-01"
}
limit: 2
order: { createdAt: desc }
) {
...histData
}
stakedTokens: metrics(
where: {
asset: { id: "ASSET_ID" }
metricKeys: ["staked_tokens"]
createdAt_gt: "2023-01-01"
}
limit: 2
order: { createdAt: desc }
) {
...histData
}
}
fragment histData on Metric {
defaultValue
createdAt
}