Im trying to send a query to Pancakeswap's router function getAmoutsOut here the code for importing the contract using ethers ABI:
const router = new ethers.Contract('0x10ED43C718714eb63d5aA57B78B54704E256024E', [
'function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)',
'function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts)'
], account);
As you can already tell the parameters are in uint256 and an array of Address type objects. how Ami supposed to send valid parameter type to the contract. I've tried a couple of built in ethers utilities functions but so far no luck. I'm 90% sure the error comes from the BNB amount.
Also side note yes ethers works fine with BSC provided you use a BSC node. much like web3. Anyway here's the code for contract deployment.
desiredCoin = 'coin contract address example';
bnb = '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c';
const amountIn = 1000000000000000000 // 1 bnb
const pairAddress = [ethers.utils.getAddress(bnb), ethers.utils.getAddress(desiredCoin)];
amounts = await router.getAmountsOut(
ethers.utils.getAddress('0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73'), //this is the factory address.
amountIn,
pairAddress);
amountOutMin = amounts.sub(amounts[1].div(slippage) //(Ik that if we were to work with hex this wouldnt be valid :/)
);