PageSourceSearch

https://docs.astar.network/assets/js/f0030569.793f3dbf.js

js astar.network collected 2026-10-03 19:23:44 UTC 14,092 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkastar_docs=self.webpackChunkastar_docs||[]).push([["4265"],{29436(e,t,r){r.r(t),r.d(t,{metadata:()=>s,default:()=>h,frontMatter:()=>i,contentTitle:()=>a,toc:()=>o,assets:()=>l});var s=JSON.parse('{"id":"build/dapp-staking/indexer/index","title":"The API and the Indexer","description":"The API is accessible from a Swagger User Interface to test the endpoints out.","source":"@site/docs/build/dapp-staking/indexer/index.md","sourceDirName":"build/dapp-staking/indexer","slug":"/build/dapp-staking/indexer/","permalink":"/docs/build/dapp-staking/indexer/","draft":false,"unlisted":false,"editUrl":"https://github.com/AstarNetwork/astar-docs/tree/main/docs/build/dapp-staking/indexer/index.md","tags":[],"version":"current","frontMatter":{},"sidebar":"tutorialSidebar","previous":{"title":"Technical Solution","permalink":"/docs/build/dapp-staking/technical_solution"},"next":{"title":"How to Install and Run","permalink":"/docs/build/dapp-staking/indexer/tutorial"}}'),n=r(74848),d=r(28453);r(91125);let i={},a="The API and the Indexer",l={},o=[{value:"Available endpoints",id:"available-endpoints",level:2},{value:"The Indexer",id:"the-indexer",level:2},{value:"Available indexes",id:"available-indexes",level:3},{value:"Coding Examples",id:"coding-examples",level:2},{value:"Examples on CodeSandBox",id:"examples-on-codesandbox",level:2}];function c(e){let t={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",p:"p",pre:"pre",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,d.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.header,{children:(0,n.jsx)(t.h1,{id:"the-api-and-the-indexer",children:"The API and the Indexer"})}),"\n",(0,n.jsxs)(t.p,{children:["The API is accessible from a ",(0,n.jsx)(t.a,{href:"https://api.astar.network/",children:"Swagger User Interface"})," to test the endpoints out."]}),"\n",(0,n.jsx)(t.admonition,{type:"info",children:(0,n.jsx)(t.p,{children:"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."})}),"\n",(0,n.jsxs)(t.table,{children:[(0,n.jsx)(t.thead,{children:(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.th,{}),(0,n.jsx)(t.th,{})]})}),(0,n.jsxs)(t.tbody,{children:[(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"UI"}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"https://api.astar.network/",children:"https://api.astar.network/"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"API"}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"https://api.astar.network/api/v3/%7Bnetwork%7D/dapps-staking/%7B...%7D",children:"https://api.astar.network/api/v3/{network}/dapps-staking/{...}"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"Github"}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"https://github.com/AstarNetwork/astar-token-api",children:"https://github.com/AstarNetwork/astar-token-api"})})]})]})]}),"\n",(0,n.jsx)(t.h2,{id:"available-endpoints",children:"Available endpoints"}),"\n",(0,n.jsxs)(t.table,{children:[(0,n.jsx)(t.thead,{children:(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.th,{children:"Data"}),(0,n.jsxs)(t.th,{children:["Endpoint, start with ",(0,n.jsx)(t.code,{children:"/api/v3/{network}/dapps-staking"})]})]})}),(0,n.jsxs)(t.tbody,{children:[(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"List of dapps registed for staking"}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"/chaindapps"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"TVL for a given network and period"}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"/tvl/{period}"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"List of stakers per dapp with total stake"}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"/stakerslist/{contractAddress}"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"Stakers count for a given network for a dapp by period"}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"/stakerscount/{contractAddress}/{period}"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"Total stakers count for a given network and period"}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"/stakerscount-total/{period}"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"Total stakers count and amount by network and period"}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"/stakers-total/{period}"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"Total lockers count and amount by network and period"}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"/lockers-total/{period}"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"Total lockers & stakers count and amount by network and period"}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"/lockers-and-stakers-total/{period}"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"All reward events by type (optional) and network"}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"/rewards/{period}/?transaction=BonusReward,Reward"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"Aggregated daily rewards by staker or dapp by period"}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"/rewards-aggregated/{address}/{period}"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"Stake amount for one participant"}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"/stake-info/{address}"})})]})]})]}),"\n",(0,n.jsx)(t.h2,{id:"the-indexer",children:"The Indexer"}),"\n",(0,n.jsxs)(t.p,{children:["The indexer is accessible from a ",(0,n.jsx)(t.a,{href:"https://squid.subsquid.io/dapps-staking-indexer-shibuya/graphql",children:"GraphQL Explorer UI"})]}),"\n",(0,n.jsxs)(t.table,{children:[(0,n.jsx)(t.thead,{children:(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.th,{}),(0,n.jsx)(t.th,{})]})}),(0,n.jsxs)(t.tbody,{children:[(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"UI"}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"https://squid.subsquid.io/dapps-staking-indexer-%7Bnetwork%7D/graphql",children:"https://squid.subsquid.io/dapps-staking-indexer-{network}/graphql"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"API"}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"https://squid.subsquid.io/dapps-staking-indexer-%7Bnetwork%7D/graphql",children:"https://squid.subsquid.io/dapps-staking-indexer-{network}/graphql"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"Github"}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"https://github.com/AstarNetwork/dapps-staking-indexer-v3",children:"https://github.com/AstarNetwork/dapps-staking-indexer-v3"})})]})]})]}),"\n",(0,n.jsx)(t.h3,{id:"available-indexes",children:"Available indexes"}),"\n",(0,n.jsxs)(t.table,{children:[(0,n.jsx)(t.thead,{children:(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.th,{children:"Table"}),(0,n.jsx)(t.th,{children:"Fields"})]})}),(0,n.jsxs)(t.tbody,{children:[(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"dapps"}
1),(0,n.jsx)(t.td,{children:"beneficiary, dappId, id, owner, registeredAt, registrationBlockNumber, stakersCount, state, unregisteredAt, unregistrationBlockNumber"})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"dappAggregatedDailies"}),(0,n.jsx)(t.td,{children:"timestamp, stakersCount, id, dappAddress"})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"rewardEvents"}),(0,n.jsx)(t.td,{children:"amount, blockNumber, contractAddress, era, id, period, tierId, timestamp, transaction, userAddress"})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"rewardAggregatedDailies"}),(0,n.jsx)(t.td,{children:"amount, beneficiary, id, timestamp"})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"stakes"}),(0,n.jsx)(t.td,{children:"amount, dappAddress, stakerAddress, blockNumber, expiredAt, expiredBlockNumber, id, timestamp"})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"stakers"}),(0,n.jsx)(t.td,{children:"amount, dappAddress, stakerAddress, id"})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"stakersCount"}),(0,n.jsx)(t.td,{children:"total"})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"stakersCountAggregatedDailies"}),(0,n.jsx)(t.td,{children:"blockNumber, id, stakersCount, stakersAmount"})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"subperiods"}),(0,n.jsx)(t.td,{children:"blockNumber, id, timestamp, type"})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"tvlAggregatedDailies"}),(0,n.jsx)(t.td,{children:"blockNumber, id, tvl, lockersCount"})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"uniqueStakerAddresses"}),(0,n.jsx)(t.td,{children:"id"})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:"uniqueLockerAddresses"}),(0,n.jsx)(t.td,{children:"id"})]})]})]}),"\n",(0,n.jsx)(t.h2,{id:"coding-examples",children:"Coding Examples"}),"\n",(0,n.jsx)(t.p,{children:"To obtain data from the API, you can use a GET request like this:"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-js",children:'async function getData() {\n  try {\n    const response = await fetch(\n      "https://api.astar.network/api/v3/shibuya/dapps-staking/chaindapps"\n    );\n    if (!response.ok) {\n      throw new Error(`HTTP error! status: ${response.status}`);\n    }\n    const data = await response.json();\n    return data;\n  } catch (error) {\n    console.error("There was a problem fetching the data: ", error);\n  }\n}\n'})}),"\n",(0,n.jsx)(t.p,{children:"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:"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-js",children:'async function tvlDaily() {\n  const response = await fetch(\n    "https://squid.subsquid.io/dapps-staking-indexer-shibuya/graphql",\n    {\n      method: "POST",\n      headers: { "Content-Type": "application/json" },\n      body: JSON.stringify({\n        query: `\n          query MyQuery {\n            tvlAggregatedDailies(orderBy: id_ASC) {\n              blockNumber\n              id\n              tvl\n            }\n          }\n        `,\n      }),\n      next: { revalidate: 10 },\n    }\n  );\n  const { data } = await response.json();\n  return data?.tvlAggregatedDailies;\n}\n'})}),"\n",(0,n.jsx)(t.h2,{id:"examples-on-codesandbox",children:"Examples on CodeSandBox"}),"\n","\n",(0,n.jsx)("iframe",{src:"https://codesandbox.io/p/github/AstarNetwork/dapps-staking-v3-indexer-and-api-demo-ui/main?embed=1&file=%2Fpages%2Findex.tsx",width:"100%",height:"1000px",display:"initial",position:"relative",allowFullScreen:!0,title:"gluneau/Graph-the-Astar-Staking-V3-GraphQL-Indexer-and-API/main",sandbox:"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"}),"\n",(0,n.jsxs)(t.p,{children:["You can also look into ",(0,n.jsx)(t.a,{href:"https://github.com/AstarNetwork/dapps-staking-v3-indexer-and-api-demo-ui",children:"this repo"})," and clone and run it:"]})]})}function h(e={}){let{wrapper:t}={...(0,d.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(c,{...e})}):c(e)}},45228(e){var t=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable;e.exports=!function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},r=0;r<10;r++)t["_"+String.fromCharCode(r)]=r;var s=Object.getOwnPropertyNames(t).map(function(e){return t[e]});if("0123456789"!==s.join(""))return!1;var n={};if("abcdefghijklmnopqrst".split("").forEach(function(e){n[e]=e}),"abcdefghijklmnopqrst"!==Object.keys(Object.assign({},n)).join(""))return!1;return!0}catch(e){return!1}}()?function(e,n){for(var d,i,a=function(e){if(null==e)throw TypeError("Object.assign cannot be called with null or undefined");return Object(e)}(e),l=1;l<arguments.length;l++){for(var o in d=Object(arguments[l]))r.call(d,o)&&(a[o]=d[o]);if(t){i=t(d);for(var c=0;c<i.length;
1c++)s.call(d,i[c])&&(a[i[c]]=d[i[c]])}}return a}:Object.assign},91125(e,t,r){r.d(t,{A:()=>i});var s=r(96540),n=r(45228),d=r.n(n);let i=({url:e,allowFullScreen:t,position:r,display:n,height:i,width:a,overflow:l,styles:o,onLoad:c,onMouseOver:h,onMouseOut:p,scrolling:x,id:u,frameBorder:j,ariaHidden:b,sandbox:g,allow:k,className:m,title:f,ariaLabel:w,ariaLabelledby:y,name:v,target:A,loading:O,importance:q,referrerpolicy:T,allowpaymentrequest:I,src:N,key:P})=>{let S=d()({src:N||e,target:A||null,style:{position:r||null,display:n||"initial",overflow:l||null},scrolling:x||null,allowpaymentrequest:I||null,importance:q||null,sandbox:g&&[...g].join(" ")||null,loading:O||null,styles:o||null,name:v||null,className:m||null,allowFullScreen:"allowFullScreen",referrerpolicy:T||null,title:f||null,allow:k||null,id:u||null,"aria-labelledby":y||null,"aria-hidden":b||null,"aria-label":w||null,width:a||null,height:i||null,onLoad:c||null,onMouseOver:h||null,onMouseOut:p||null,key:P||"iframe"}),C=Object.create(null);for(let e of Object.keys(S))null!=S[e]&&(C[e]=S[e]);for(let e of Object.keys(C.style))null==C.style[e]&&delete C.style[e];if(C.styles)for(let e of Object.keys(C.styles))C.styles.hasOwnProperty(e)&&(C.style[e]=C.styles[e]),Object.keys(C.styles).pop()==e&&delete C.styles;if(t)if("allow"in C){let e=C.allow.replace("fullscreen","");C.allow=`fullscreen ${e.trim()}`.trim()}else C.allow="fullscreen";return j>=0&&!C.style.hasOwnProperty("border")&&(C.style.border=j),s.createElement("iframe",Object.assign({},C))}},28453(e,t,r){r.d(t,{R:()=>i,x:()=>a});var s=r(96540);let n={},d=s.createContext(n);function i(e){let t=s.useContext(d);return s.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:i(e.components),s.createElement(d.Provider,{value:t},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.