|
| 1 | +# The API and the Indexer |
| 2 | + |
| 3 | +The API is accessible from a [Swagger User Interface](https://api.astar.network/) to test the endpoints out. |
| 4 | + |
| 5 | +:::info |
| 6 | +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. |
| 7 | +::: |
| 8 | + |
| 9 | +| | | |
| 10 | +| ------ | -------------------------------------------------------------- | |
| 11 | +| UI | https://api.astar.network/ | |
| 12 | +| API | https://api.astar.network/api/v3/{network}/dapps-staking/{...} | |
| 13 | +| Github | https://github.com/AstarNetwork/astar-token-api | |
| 14 | + |
| 15 | +## Available endpoints |
| 16 | + |
| 17 | +| Data | Endpoint, start with `/api/v3/{network}/dapps-staking` | |
| 18 | +| ------------------------------------------------------ | ------------------------------------------------------ | |
| 19 | +| List of dapps registed for staking | `/chaindapps` | |
| 20 | +| TVL for a given network and period | `/tvl/{period}` | |
| 21 | +| List of stakers per dapp with total stake | `/stakerslist/{contractAddress}` | |
| 22 | +| Stakers count for a given network for a dapp by period | `/stakerscount/{contractAddress}/{period}` | |
| 23 | +| Total stakers count for a given network and period | `/stakerscount-total/{period}` | |
| 24 | +| All reward events by type (optional) and network | `/rewards/{period}/?transaction=BonusReward,Reward` | |
| 25 | +| Aggregated daily rewards by staker or dapp by period | `/rewards-aggregated/{address}/{period}` | |
| 26 | +| Stake amount for one participant | `/stake-info/{address}` | |
| 27 | + |
| 28 | +## The Indexer |
| 29 | + |
| 30 | +The indexer is accessible from a [GraphQL Explorer UI](https://squid.subsquid.io/dapps-staking-indexer-shibuya/graphql). |
| 31 | + |
| 32 | +| | | |
| 33 | +| ------ | -------------------------------------------------------------------- | |
| 34 | +| UI | https://squid.subsquid.io/dapps-staking-indexer-shibuya/graphql | |
| 35 | +| API | https://squid.subsquid.io/dapps-staking-indexer-shibuya/graphql | |
| 36 | +| Github | https://github.com/AstarNetwork/dapps-staking-indexer-v3 | |
| 37 | + |
| 38 | +### Available indexes |
| 39 | + |
| 40 | +| Table | Fields | |
| 41 | +| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | |
| 42 | +| dapps | beneficiary, dappId, id, owner, registeredAt, registrationBlockNumber, stakersCount, state, unregisteredAt, unregistrationBlockNumber | |
| 43 | +| dappAggregatedDailies | timestamp, stakersCount, id, dappAddress | |
| 44 | +| rewardEvents | amount, blockNumber, contractAddress, era, id, period, tierId, timestamp, transaction, userAddress | |
| 45 | +| rewardAggregatedDailies | amount, beneficiary, id, timestamp | |
| 46 | +| stakes | amount, dappAddress, stakerAddress, blockNumber, expiredAt, expiredBlockNumber, id, timestamp | |
| 47 | +| stakers | amount, dappAddress, stakerAddress, id | |
| 48 | +| stakersCount | total | |
| 49 | +| stakersCountAggregatedDailies | blockNumber, id, stakersCount, stakersAmount | |
| 50 | +| subperiods | blockNumber, id, timestamp, type | |
| 51 | +| tvlAggregatedDailies | blockNumber, id, tvl | |
| 52 | +| uniqueStakerAddresses | id | |
| 53 | + |
| 54 | +## Coding Examples |
| 55 | + |
| 56 | +To obtain data from the API, you can use a GET request like this: |
| 57 | + |
| 58 | +```js |
| 59 | +async function getData() { |
| 60 | + try { |
| 61 | + const response = await fetch('https://api.astar.network/api/v3/shibuya/dapps-staking/chaindapps'); |
| 62 | + if (!response.ok) { |
| 63 | + throw new Error(`HTTP error! status: ${response.status}`); |
| 64 | + } |
| 65 | + const data = await response.json(); |
| 66 | + return data; |
| 67 | + } catch (error) { |
| 68 | + console.error('There was a problem fetching the data: ', error); |
| 69 | + } |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +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: |
| 74 | + |
| 75 | +```js |
| 76 | +async function tvlDaily() { |
| 77 | + const response = await fetch( |
| 78 | + "https://squid.subsquid.io/dapps-staking-indexer-shibuya/graphql", { |
| 79 | + method: "POST", |
| 80 | + headers: { "Content-Type": "application/json" }, |
| 81 | + body: JSON.stringify({ |
| 82 | + query: ` |
| 83 | + query MyQuery { |
| 84 | + tvlAggregatedDailies(orderBy: id_ASC) { |
| 85 | + blockNumber |
| 86 | + id |
| 87 | + tvl |
| 88 | + } |
| 89 | + } |
| 90 | + `, |
| 91 | + }), |
| 92 | + next: { revalidate: 10 } |
| 93 | + } |
| 94 | + ); |
| 95 | + const { data } = await response.json(); |
| 96 | + return data?.tvlAggregatedDailies; |
| 97 | +} |
| 98 | +``` |
| 99 | +
|
| 100 | +## Examples on CodeSandBox |
| 101 | +
|
| 102 | +```mdx-code-block |
| 103 | +import Iframe from 'react-iframe'; |
| 104 | + |
| 105 | +<iframe src="https://codesandbox.io/p/github/AstarNetwork/dapps-staking-v3-indexer-and-api-demo-ui/main?embed=1&file=%2Fpages%2Findex.tsx" |
| 106 | + width="100%" |
| 107 | + height="1000px" |
| 108 | + display="initial" |
| 109 | + position="relative" |
| 110 | + allowFullScreen |
| 111 | + title="gluneau/Graph-the-Astar-Staking-V3-GraphQL-Indexer-and-API/main" |
| 112 | + sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts" |
| 113 | +/> |
| 114 | +``` |
| 115 | +
|
| 116 | +You can also look into [this repo](https://github.com/AstarNetwork/dapps-staking-v3-indexer-and-api-demo-ui) and clone and run it: |
0 commit comments