2

I am trying to query the pancakeSwap token pair contract for the reserves, and since I am trying to get it for 10000 tokens at a single time.

My current solution is to basically loop over the 10000 tokens and query each smart contract of that coin pair to get the reserves which happen to be very consuming in physical resources.

Is there a way to get all the reserves in a single smart contract query?

1 Answer 1

1

Here's an option for using in future... it currently looks like there's a failure in compiling the dataset, so it's only partially being returned.

You could use the PancakeSwap SubGraph: https://thegraph.com/explorer/subgraph/bscnodes/pancakeswap

Here's the query:

{
  pairs(orderDirection: asc) {
    id
    reserve0
    reserve1
    reserveETH
    reserveUSD
  }
}
2
  • that's nice, but my question is how do they get that data ? is it different from querying the blockchain every second? Commented May 8, 2021 at 9:24
  • 1
    The Graph is an indexer that stores data in a GraphQL database, which can then be queried. Different SubGraphs have different indexing rules - so the PackageSwap SubGraph is set up to listen for events from the factory contract so they can track any new pairs created. I believe they then listen to each created contract. (So yes, they dynamically increase the number of listeners, which is easy to do when you're a large service with access to funds and cloud services.) Commented May 8, 2021 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.