メインコンテンツへスキップする

The API and the Indexer

The API is accessible from a Swagger User Interface to test the endpoints out.

info

The API is available as a complimentary endpoint for developers with restricted usage and may not be appropriate for high-demand scenarios and continuous fetching of data. Users should note that excessive use could lead to instability of the free Token API. For those requiring high data availability, it is advisable to host their own API.

UIhttps://api.astar.network/
APIhttps://api.astar.network/api/v3/{network}/dapps-staking/{...}
Githubhttps://github.com/AstarNetwork/astar-token-api

Available endpoints

DataEndpoint, start with /api/v3/{network}/dapps-staking
List of dapps registed for staking/chaindapps
TVL for a given network and period/tvl/{period}
List of stakers per dapp with total stake/stakerslist/{contractAddress}
Stakers count for a given network for a dapp by period/stakerscount/{contractAddress}/{period}
Total stakers count for a given network and period/stakerscount-total/{period}
Total stakers count and amount by network and period/stakers-total/{period}
Total lockers count and amount by network and period/lockers-total/{period}
Total lockers & stakers count and amount by network and period/lockers-and-stakers-total/{period}
All reward events by type (optional) and network/rewards/{period}/?transaction=BonusReward,Reward
Aggregated daily rewards by staker or dapp by period/rewards-aggregated/{address}/{period}
Stake amount for one participant/stake-info/{address}

The Indexer

The indexer is accessible from a GraphQL Explorer UI

UIhttps://squid.subsquid.io/dapps-staking-indexer-{network}/graphql
APIhttps://squid.subsquid.io/dapps-staking-indexer-{network}/graphql
Githubhttps://github.com/AstarNetwork/dapps-staking-indexer-v3

Available indexes

TableFields
dappsbeneficiary, dappId, id, owner, registeredAt, registrationBlockNumber, stakersCount, state, unregisteredAt, unregistrationBlockNumber
dappAggregatedDailiestimestamp, stakersCount, id, dappAddress
rewardEventsamount, blockNumber, contractAddress, era, id, period, tierId, timestamp, transaction, userAddress
rewardAggregatedDailiesamount, beneficiary, id, timestamp
stakesamount, dappAddress, stakerAddress, blockNumber, expiredAt, expiredBlockNumber, id, timestamp
stakersamount, dappAddress, stakerAddress, id
stakersCounttotal
stakersCountAggregatedDailiesblockNumber, id, stakersCount, stakersAmount
subperiodsblockNumber, id, timestamp, type
tvlAggregatedDailiesblockNumber, id, tvl, lockersCount
uniqueStakerAddressesid
uniqueLockerAddressesid

Coding Examples

To obtain data from the API, you can use a GET request like this:

async function getData() {
try {
const response = await fetch(
"https://api.astar.network/api/v3/shibuya/dapps-staking/chaindapps"
);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error("There was a problem fetching the data: ", error);
}
}

To get data from the indexer directly in case the enpoint you want to use does not include the data you're looking for, uses a POST request like so:

async function tvlDaily() {
const response = await fetch(
"https://squid.subsquid.io/dapps-staking-indexer-shibuya/graphql",
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
query: `
query MyQuery {
tvlAggregatedDailies(orderBy: id_ASC) {
blockNumber
id
tvl
}
}
`,
}),
next: { revalidate: 10 },
}
);
const { data } = await response.json();
return data?.tvlAggregatedDailies;
}

Examples on CodeSandBox

You can also look into this repo and clone and run it: