2

i am trying to create and send a transaction to https://app.uniswap.org using SDK https://uniswap.org/docs/v2/smart-contracts/router02/

uniswap has two functions (swapExactTokensForETH and swapExactTokensForETHSupportingFeeOnTransferTokens) - tokens with and without fees. how to define a coin with or without commission? Otherwise, if sent incorrectly, the transaction will fail.

3

I had to read how the pancakeswap frontend does this.

Basically, you calculate gas for BOTH methods. And the one that does not return an error, is the one you use.

e.g:

contract.methods.swapExactTokensForETHSupportingFeeOnTransferTokens(
  Web3.utils.toHex(amountIn), Web3.utils.toHex(0), path, to, deadline
).estimateGas({
  from: activeAccount.address,
  gas: 5000000,
  value: web3.utils.toHex(0)
}, (error, result) => {
  console.log(error);
  console.log('swapExactTokensForETHSupportingFeeOnTransferTokens: ', result);
});

contract.methods.swapExactTokensForETH(
  Web3.utils.toHex(amountIn), Web3.utils.toHex(0), path, to, deadline
).estimateGas({
  from: activeAccount.address,
  gas: 5000000,
}, (error, result) => {
  console.log(error);
  console.log('swapExactTokensForETH: ', result);
});

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.