Skip to content

Latest commit

 

History

History
81 lines (70 loc) · 2.73 KB

README.md

File metadata and controls

81 lines (70 loc) · 2.73 KB

access-grants-thegraph

Describes Subgraphs for querying EVM access grant contracts using GraphQL.

For example, this query:

{
  grantAddeds(first: 2, where: {lockedUntil_gt: 0}) {
    owner
    grantee
    dataId
    lockedUntil
    blockTimestamp
    transactionHash
  }
}

Yields the following result:

{
  "data": {
    "grantAddeds": [
      {
        "owner": "0x23689aec7dfd6b6f707dbf74b5581d84e8f3c813",
        "grantee": "0x1d38049068199e2cea6490a0a458991ff69f523f",
        "dataId": "6f9d07ee-3a17-4559-ac94-3079a7ee4250",
        "lockedUntil": "1713109836",
        "blockTimestamp": "1713106248",
        "transactionHash": "0x2c37e5844d8d5854dad8ff0dc95525ff7b3179e8a90c31ec1d918a9ea34dd3cc"
      },
      {
        "owner": "0x246571f6bd246e257edac94650a93b85494b53a0",
        "grantee": "0x1d38049068199e2cea6490a0a458991ff69f523f",
        "dataId": "0305f374-6155-4e87-8514-e64ca9522aca",
        "lockedUntil": "1713822575",
        "blockTimestamp": "1713819000",
        "transactionHash": "0x39f5b98c29f97afe10324f27450e0526eb76c950eb42ee56bf89b233c5086a9a"
      }
    ]
  }
}

Querying

You can use the Studio to query a limited amount of records:

For more control you can use a GraphQL client as shown below. You can see a demo in CodePen.

import { ApolloClient, InMemoryCache, gql } from "@apollo/client";

(async () => {
  const client = new ApolloClient({
    uri: "https://api.studio.thegraph.com/query/72558/idos-ags-ethereum-sepolia/0.0.6",
    cache: new InMemoryCache(),
  });

  let results = [];
  const pageSize = 1000;
  for (let page = 0;; page++) {
    const { data: { grantAddeds } } = await client.query({ query: gql(`
      query {
        grantAddeds (first: ${pageSize}, skip: ${page * pageSize}) {
          owner
          grantee
          dataId
        }
      }`
    )});
    
    results = [...results, ...grantAddeds];
    
    if (grantAddeds.length < pageSize || grantAddeds.length === 0) break;
  }

  console.log(results);
})();