Skip to main content

Practical Query Samples

This section contains samples for the API.

JavaScript and Python Setup

See the Quick Start for a step-by-step guide on how to get started with the API.

Get Reward Rate for Ethereum

The following code snippet shows how to get the reward rate 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

This query returns the staked_tokens metric for Ethereum.

{
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 and their Balance

The following code snippet shows how to get the validators of a provider for Cosmos and their balance. The provider is unspecified, you can specify it by adding the providers name subquery to the query like this providers(where:{slugs:["PROVIDER_SLUG"]}, limit: 1).

The query filters the reward options to only include those of the type pos (proof-of-stake) and the input asset Cosmos. The query limits the number of reward options to 10. For each reward option, the query returns the information about a single provider's slug and the data about 100 validators participating. For each validator, the query returns the address, status label, and the metric information about the number of staked tokens. The query limits the number of metrics returned to only 1.

{
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 for an asset with different providers and validators with addresses

The following query shows how to get the validators of a provider for Cosmos and their reward_rate. This query is similar to the one above. The difference is, that we are fetching a different metric to get the reward instead of the staked tokens. We order by it instead.

{
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

This query returns the ID for an asset. The ID is needed to query for metrics.

{
assets(where: { slugs: ["ethereum-2-0"] }, limit: 1) {
slug
id
}
}

Retrieving Historical Metrics for a Specific Asset

This query retrieves data for three different metrics for a specific asset identified by its ID, with a createdAt date greater than 2023-01-01.
The data for each metric is limited to 2 or 3 items, ordered by creation date in descending order. The retrieved data for each metric includes the defaultValue and createdAt. The data for each metric is collected using the fragment histData to DRY up the code.

{
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
}