2

I'm trying to create a transaction but I can't figure out how to set the gas price. Here's my current code, but according to https://uniswap.org/docs/v2/smart-contracts/router02/#swapexacttokensfortokens there is nowhere to define gas price if I'd like to have a fast transaction

  const tx = await router.swapExactTokensForTokens(
    amountIn,
    amountOutMin,
    [WETH_ADDRESS, CONTRACT],
    RECIPIENT,
    Date.now() + 1000 * 60 * 10 //10 minutes
  );

Code below is how I create the router

const router = new ethers.Contract(
  UNISWAP_ROUTER,
  [
    'function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)',
    'function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)'
  ],
  account
);
2
  • Have you managed to do this? Im sorry i know this is answer only but I’m curious... ive been searching the internet up and down May 4 '21 at 9:05
  • did you not read the answer
    – H Johnson
    Jul 21 '21 at 20:41
3

You can specify the transaction fields when calling a contract function like so:

 var options = { gasPrice: 1000000000}; // in wei

 const tx = await router.swapExactTokensForTokens(
    amountIn,
    amountOutMin,
    [WETH_ADDRESS, CONTRACT],
    RECIPIENT,
    Date.now() + 1000 * 60 * 10, //10 minutes
    options
  );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.