Fetching Data
This guide will illustrate how to fetch data from the SDK and details on instances where the SDK needs on-chain data and elaborates on strategies that you can use to fetch data.
#
Case 1: Fetching Token InformationFor the SDK to perform queries and actions, it needs data in the format it can work with. For example, for a token, it requires the chainId, address and its decimals.
- The token address should be a manual input. Refer to this section for some popular token addresses
- The chainId depends on the chain which we are on (e.g. it's
1
if we are onmainnet
) - The SDK can then look up other token related information via Fetcher.fetchTokenData
Example:
#
Case 2: PoolsAfter getting the details for a pair of tokens, you can retrieve pools for the token pair via Fetcher.fetchPairData. This is useful for when you want information on the reserves and virtual reserves of the pools.
Alternatively, you can retrieve just the pool addresses instead of the entire pool information for the token pair via Fetcher.fetchPairAddresses.
As an example, let's try to get data for the USDC-DAI pair.
Note that these values can change as frequently as every block, and should be kept up-to-date.