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
Parameter | Description | Type | Required | Default |
---|---|---|---|---|
chainId | Chain ID for price quotes. | ChainId | true | Required parameter. |
tokenAddress | Address of token contract. | 0x{string} | false | Required to fetch the USD price of one token. |
srcTokenAddress | Address of the source token contract. | 0x{string} | false | Required to fetch the exchange rate between two tokens. |
dstTokenAddress | Address of the destination token contract. | 0x{string} | false | Required to fetch the exchange rate between two tokens. |
amount | Quantity of the source token - e.g., 2 USDC = $2 | number | false | 1 |
wei | Specify whether the amount is a bigint | boolean | false | false |
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
}