Version: V1

# 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 Information#

For 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 on mainnet)
• The SDK can then look up other token related information via Fetcher.fetchTokenData

Example:

import { ChainId, Token, Fetcher } from '@dynamic-amm/sdk';
const chainId = ChainId.MAINNET;
const tokenAddress = '0xdeFA4e8a7bcBA345F687a2f1456F5Edd9CE97202'; // must be checksummed
const KNC: Token = await Fetcher.fetchTokenData(chainId, tokenAddress);
console.log({ KNC });
// {
// "KNC": {
// "decimals": 18,
// "chainId": 1,
// }
// }

### Case 2: Pools#

After 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.

import { ChainId, Token, Fetcher, Pair } from '@dynamic-amm/sdk';
// Note: DMM Factory address will differ depending on the chain you are using
const DAI = new Token(
ChainId.MAINNET,
'0x6B175474E89094C44Da98b954EedeAC495271d0F',
18,
);
const USDC = new Token(
ChainId.MAINNET,
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
18,
);
const pools: Pair[] = await Fetcher.fetchPairData(DAI, USDC, DMMFactoryAddress);