Skip to content

Token Info & Prices

Base Url: api.decentscan.xyz
Endpoint: /getTokenPrice

Decent provides a powerful token data API to return token prices across supported chains. This endpoint solves several distinct challenges:

  • Existing token data endpoints are either very expensive or require significant developer effort to set up.
  • Applications need to accept multiple tokens as viable payment options but quote prices in a standard unit for a consistent user experience.
  • Many chains do not have exchanges or other means of providing accurate price quotes for their ecosystem tokens.
  • ERC20 tokens often have a different number of decimals, which forces developers to read the token's number of decimals from the contract to ensure accurate unit conversions.

Let's be honest, the status quo stinks.

Decent's pricing API enables you to quickly fetch key token information, the USD price, or exchange rate between two tokens on any chain that Decent supports.

This API uses Uniswap as a price oracle. We source quotes from the deepest liquidity pool for a token and extend those quotes across chains to provide accurate token data and price information even on chains with little to no DEX liquidity. Token prices refresh every five minutes.

Query Parameters

ParameterDescriptionTypeRequiredDefault
chainIdChain ID for price quotes.ChainIdtrueRequired parameter.
tokenAddressAddress of token contract.0x{string}falseRequired to fetch the USD price of one token.
srcTokenAddressAddress of the source token contract.0x{string}falseRequired to fetch the exchange rate between two tokens.
dstTokenAddressAddress of the destination token contract.0x{string}falseRequired to fetch the exchange rate between two tokens.
amountQuantity of the source token - e.g., 2 USDC = $2numberfalse1
weiSpecify whether the amount is a bigintbooleanfalsefalse

Sample Request

Node Fetch
  // Use this configuration to fetch information and the USD price for one token.
  const singleTokenQuery = new URLSearchParams({
    chainId: 1,
    tokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'
  });
 
  // Use this configuration to fetch information for two tokens and their exchange rate.
  const tokenPairQuery = new URLSearchParams({
    chainId: 1,
    srcTokenAddress: '0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE',
    dstTokenAddress: '0x6982508145454Ce325dDbE47a25d4ec3d2311933',
    amount: 3000000000000000000,
    wei: true
  });
 
  const options = { method: 'GET', headers: { 'x-api-key': `${process.env.DECENT_API_KEY}` }}
 
  fetch(`https://api.decentscan.xyz/getTokenPrice?{tokenQuery}`, options)
    .then(response => response.json())
    .then(response => console.log(response))
    .catch(err => console.error(err));

Response Schema

Single Token Response

Response
{
  token: 
  {
    name: string,
    symbol: string,
    decimals: number,
    address: string
  },
  usdPrice: number
}

Token Pair Response

For example, the tokenPairQuery above provides the token information for SHIBA INU & Pepe and how much Pepe you could receive for 3 SHIB.

Response
{
  srcToken: {
    name: number,
    symbol: string,
    decimals: number,
    address: `0x${string}`
  },
  dstToken: {
    name: string,
    symbol: string,
    decimals: number,
    address: `0x${string}`
  },
  pairConversion: number
}