-
Describe the bug Error currently occurs on Error Message:
Unsure if I'm doing anything incorrectly or if this is a genuine issue? Reproduction steps async () => {
await provider.ready;
const wallet = new ethers.Wallet(privatekey, provider);
const account = wallet.connect(provider);
const factory = new ethers.Contract(
addresses.PANCAKESWAP_FACTORY_ADDR_V2,
pancakeswapFactoryAbi,
account
);
const router = new ethers.Contract(
addresses.PANCAKESWAP_ROUTER_ADDR_V2,
pancakeswapRouterAbi,
account
);
const tokenIn = data.WBNB;
const tokenOut = data.to_PURCHASE;
const tokenContract = new ethers.Contract(data.to_PURCHASE, BEP20, account);
const pair = new ethers.Contract(pairAddress, pancakeswapPairAbi, account);
// Buy x amount of the new token with wBNB
const amountIn = ethers.utils.parseUnits(`${data.AMOUNT_OF_WBNB}`, 'ether');
const amounts = await router.getAmountsOut(amountIn, [tokenIn, tokenOut]);
const amountOutMin = amounts[1].sub(amounts[1].div(`${data.Slippage}`));
const tx = await router.swapExactTokensForTokens(
amountIn,
amountOutMin,
[tokenIn, tokenOut],
data.recipient,
Date.now() + 1000 * 60 * 2, // 2 minutes
{
'gasLimit': data.gasLimit,
'gasPrice': ethers.utils.parseUnits(`${data.gasPrice}`, 'gwei')
}
);
console.log(tx, 'tx');
const unsignedTx = await wallet.populateTransaction(tx)
console.log(getMethods(signer), 'signer')
// console.log(signer.checkTransaction(tx), 'tx');
const signedTx = await wallet.sendTransaction(unsignedTx)
const receipt = await signedTx.wait();
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Your If you are trying to manually control that, you can use Make sense? (moving to discussions) |
Beta Was this translation helpful? Give feedback.
Your
router
is connected to account, so that call torouter.swapExactTokensForToke s
is sending the transaction. Which means the transaction you are getting back is signed and sent to the network. It is too late to try populating it by then.If you are trying to manually control that, you can use
router.populateTransaction.swapExactTokensForTokens
. Or you can just pass yourwallet
into therouter
directly and skip all the manual work.Make sense? (moving to discussions)