Reputation: 893
i have the following code which should give me the swap value for pair of tokens on pancake
const ethers = require('ethers');
const {routerAddress,fromAddress,toAddress}=require("./AddressList");
const {erc20ABI,routerABI}=require("./AbiInfo");
const provider= new ethers.providers.JsonRpcProvider("https://bsc-dataseed1.binance.org/")
const routerInstance = new ethers.Contract(
routerAddress,routerABI,provider
)
const quantityFetch=async(humanInput)=>{
const token1 = new ethers.Contract(
fromAddress,erc20ABI,provider
);
const token2=new ethers.Contract(
toAddress,erc20ABI,provider
);
const decimal1 = await token1.decimals();
const decimal2 = await token2.decimals();
const amountIn = ethers.utils.parseUnits(humanInput,decimal1).toString();
const amountsOut = await routerInstance.getAmountsOut(amountIn,[
fromAddress,toAddress
])
const humanOutput = ethers.utils.formatUnits(amountsOut[1].toString(),
decimal2)
console.log(humanOutput)
}
quantityFetch("1")
when iam executing the code for the pair Cake/ETH iam getting correct value but if i execute for any other pair like Cake/AIOZ it doesnt give me right values what could be the reason ?
here are the value of contracts
const routerAddress="0x10ED43C718714eb63d5aA57B78B54704E256024E";
const fromAddress="0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82"; //Cake
const toAddress="0x33d08D8C7a168333a85285a68C0042b39fC3741D";//AIOZ
module.exports={
routerAddress,
fromAddress,
toAddress
}
Upvotes: 0
Views: 44