Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
82 lines (65 sloc) 2.95 KB

Data

  • getTokenReserves
    • Function Signature
    • Input Parameters
    • Example Usage

getTokenReserves

This function fetches Uniswap reserve data for a given token address on a given network.

{% hint style="info" %} If only a chain id is specified, the Ethereum node used to fulfill data requests is determined by ethers.getDefaultProvider, else it is the one specified by the passed provider. {% endhint %}

{% hint style="danger" %} This function throws an error if the provided tokenAddress is not a token with a Uniswap exchange. {% endhint %}

Function Signature

export async function getTokenReserves(
  tokenAddress: string,
  chainIdOrProvider: ChainIdOrProvider = 1
): Promise<TokenReservesNormalized>

Input Parameters

Parameter Type Description
tokenAddress string The checksummed address of a token with a Uniswap exchange.
chainIdOrProvider ChainIdOrProvider A supported chain id (1, 3, 4, or 42), or an underlying web3 provider connected to a chain with a supported chain id.

Example Usage

const tokenAddress = '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359' // DAI Mainnet
const chainIdOrProvider: ChainIdOrProvider = 1 // could be e.g. window.ethereum instead

const tokenReserves: TokenReservesNormalized = await getTokenReserves(tokenAddress, chainIdOrProvider)

/*
{
  // details for the passed token
  token: {
    chainId: 1,
    address: '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359',
    decimals: 18
  },

  // details for the Uniswap exchange of the passed token
  exchange: {
    chainId: 1,
    address: '0x09cabEC1eAd1c0Ba254B09efb3EE13841712bE14',
    decimals: 18
  },
  
  // details for the ETH portion of the reserves of the passed token
  ethReserve: {
    token: {
      chainId: 1,
      address: 'ETH',
      decimals: 18
    },
    amount: <BigNumber>
  },

  // details for the token portion of the reserves of the passed token
  tokenReserve: {
    token: {
      chainId: 1,
      address: '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359',
      decimals: 18
    },
    amount: <BigNumber>
  }
}
*/
You can’t perform that action at this time.