I would like to format the price data I get back from the getAmountsOut() function into the correct tokens decimals. Here's part of my code-
const urlRouter = `https://api.bscscan.com/api?module=contract&action=getabi&address=${pancakeRouterAddress}&apikey=${bscScanAPI}`
const resRouter = await fetch(urlRouter)
var abiRouter = '';
abiRouter = await resRouter.json()
abiRouter = JSON.parse(abiRouter.result)
const pancakeRouter = new web3.eth.Contract(abiRouter,pancakeRouterAddress)
let price = await pancakeRouter.methods.getAmountsOut(_swapAmount,[token0, token1]).call()
console.log(price[1])
I get returned -
0
Instead I want it to look something more like '0.003180' where I can actually see the values to use for comparison. I tried using this but I got returned just '0.0'.
price = ethers.utils.formatUnits(price[1],18)
console.log(Number(price))
Any help is appreciated, thanks.