Skip to main content
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


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,
// "address": "0xdeFA4e8a7bcBA345F687a2f1456F5Edd9CE97202"
// }
// }

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
// See:
const DMMFactoryAddress = '0x833e4083B7ae46CeA85695c4f7ed25CDAd8886dE';
const DAI = new Token(
const USDC = new Token(
const pools: Pair[] = await Fetcher.fetchPairData(DAI, USDC, DMMFactoryAddress);
const poolAddresses: string[] = await Fetcher.fetchPairAddresses(

Note that these values can change as frequently as every block, and should be kept up-to-date.