This is my code.
const amountIn = ethers.utils.parseUnits('0.1', 'ether'); //ether is the measurement, not the coin
const amounts = await router.getAmountsOut(amountIn, [buyToken, sellToken]);
const amountOutMin = amounts[1].sub(amounts[1].div(10)); // math for Big numbers in JS
console.log(`
~~~~~~~~~~~~~~~~~~~~
Buying new token
~~~~~~~~~~~~~~~~~~~~
buyToken: ${amountIn.toString()} ${buyToken} (WBNB)
sellToken: ${amountOutMin.toString()} ${sellToken}
`);
const tx = await router.swapExactTokensForTokens(
amountIn,
amountOutMin,
[buyToken, sellToken],
addresses.me,
Date.now() + 1000 * 60 * 5 //5 minutes
);
const receipt = await tx.wait();
console.log('Transaction receipt');
console.log(receipt);
But there's nowhere that gas is added to this. I only knew how to send signed transactions but now I find the swapExactTokensForTokens function and I really can't work out how to send gas when using it.