I have been successfully swapping erc20 tokens using the exactInputSingle method, but I can't figure out how to do a swap with ETH on either side of the swap and I can't find it in the docs or anywhere else..

I've tried using the multicall function with wrapETH and unwrapWETH9 but I always get STF errors when doing so.

Any help or an example would be so greatly appreciated, I've been stuck for a very long time.

  • STF means that SafeTransferFrom failed: either you don't have the correct approvals, or insufficient amounts in wallet.
    – kfx
    Oct 25, 2022 at 6:09

1 Answer 1


to swap token, you have to interact with the swapRouterContract and allow that contract to get ether out of your wallet. For this, you need to use ERC20 contract's approve function to allow swapRouterContract. First step is create an ERC20 contract

  const provider = new ethers.providers.JsonRpcProvider(URL)
  // this is goerli
  // https://goerli.etherscan.io/token/0xb4fbf271143a4fbf7b91a5ded31806e42b2208d6
  // you could find erc20 abi online
  const ERC20Contract = new ethers.Contract(addressOfWeth, ERC20ABI, provider);

then you have to call the approve

await ERC20Contract
    // connectedWallet is the signer
    // define approvalAmount
    .approve(swapRouterAddress, approvalAmount)

// https://docs.uniswap.org/protocol/reference/deployments
const swapRouterAddress = "0xE592427A0AEce92De3Edee1F18E0157C05861564";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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