wallet = ethers.Wallet.fromMnemonic(mnemonic)
// console.log(wallet.address)
const signer = wallet.connect(provider);
// console.log(signer)
const routerInstance = new ethers.Contract(routerAddress, routerABI, signer);
const token1 = new ethers.Contract(fromAddress, erc20ABI, provider);
const token2 = new ethers.Contract(toAddress, erc20ABI, provider);
//--------------------------Input variabals--------------------------//
const gasLimit = 20000
//--------------------------Token Swap Function--------------------------//
const TokenSwap = async(amount, fromAddress, toAddress) => {
const decimal1 = await token1.decimals()
const decimal2 = await token2.decimals()
// const amountIn = ethers.utils.parseUnits(amount, decimal1).toString();
// const amountIn = ethers.BigNumber.from(amount, decimal1).toString();
const amountIn = ethers.utils.parseEther(amount).toString();
const amountOut = await routerInstance.getAmountsOut(amountIn, [fromAddress, toAddress])
console.log(amountIn)
const output = ethers.utils.formatUnits(amountOut[1].toString(), decimal2)
console.log(output)
console.log(Date.now() + 1000 * 60 * 10)
const tx = await routerInstance.swapTokensForExactTokens(
amountIn,
amountOut,
[fromAddress, toAddress],
wallet.address,
Date.now() + 1000 * 60 * 5,
)
}
amount = "0.000000000000002";
TokenSwap(amount, fromAddress, toAddress);
^
Here is my error:
D:\blockchain\Volume Bot -ruv\node_modules\@ethersproject\logger\lib\index.js:238
var error = new Error(message);
Error: invalid BigNumber value (argument="value", value=[{"type":"BigNumber","hex":"0x07d0"},{"type":"BigNumber","hex":"0x00"}], code=INVALID_ARGUMENT, version=bignumber/5.7.0)
at Logger.makeError (D:\blockchain\Volume Bot -ruv\node_modules\@ethersproject\logger\lib\index.js:238:21)
at Logger.throwError (D:\blockchain\Volume Bot -ruv\node_modules\@ethersproject\logger\lib\index.js:247:20)
at Logger.throwArgumentError (D:\blockchain\Volume Bot -ruv\node_modules\@ethersproject\logger\lib\index.js:250:21)
at BigNumber.from (D:\blockchain\Volume Bot -ruv\node_modules\@ethersproject\bignumber\lib\bignumber.js:239:23)
at NumberCoder.encode (D:\blockchain\Volume Bot -ruv\node_modules\@ethersproject\abi\lib\coders\number.js:36:39)
at D:\blockchain\Volume Bot -ruv\node_modules\@ethersproject\abi\lib\coders\array.js:74:19
at Array.forEach (<anonymous>)
at pack (D:\blockchain\Volume Bot -ruv\node_modules\@ethersproject\abi\lib\coders\array.js:60:12)
at TupleCoder.encode (D:\blockchain\Volume Bot -ruv\node_modules\@ethersproject\abi\lib\coders\tuple.js:71:33)
at AbiCoder.encode (D:\blockchain\Volume Bot -ruv\node_modules\@ethersproject\abi\lib\abi-coder.js:91:15) { reason: 'invalid BigNumber value', code: 'INVALID_ARGUMENT', argument: 'value', value: [
BigNumber { _hex: '0x07d0', _isBigNumber: true },
BigNumber { _hex: '0x00', _isBigNumber: true } ] }
Node.js v20.9.0