FAQ
This page contains some useful advices that questions that can be arise while use Fanbase API and implement it on custom project.
How to handle big number exception returned from API? Depending on the property of DEX platform, data type of amount or price values returned from API can be string or object. At this time, string refers normal safe number value and object is Big Number object. e.g
Endpoint: https://agg20.fanbase.io/v1/quotes This endpoint returns quote list that includes output token amount. 1INCH returns output amount data as a safe number string and the other DEXs return that data as a Big Number object. How to handle this problem? See following code.
if(typeof quote.toTokenAmount === "string"){
amount = quote.toTokenAmount;
}
else {
amount = ethers.parseUnits(quote.toTokenAmount, outputToken.decimals);
// amount = parseInt(quote.toTokenAmount, 16) / 10 ** outputToken.decimals; // (alternative)
}
Last updated