0

I've been trying to swap some DAI which I sent to the contract to WETH. However even after trying to change the contract a bit I always get the same error output: transact to GibIhmHart.runUniswap errored: Error: Returned error: VM Exception while processing transaction: revert UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT Tried changing up the parameters of expectedAmountOut but still no results. Any help is much appreciated... been coding for weeks on this project and feel like I'm getting close. Thought a few times about throwing my comp against the wall... Thanks in advance

EDIT: Using psolidity 0.8.0

EDIT II:

function runUniswap(uint amount, address fromtoken, address totoken, address ExchangeContract) public returns (uint){
        IERC20 srcToken = IERC20(fromtoken);
        IERC20 dstToken = IERC20(totoken);
        srcToken.transfer(address(this), amount);

        IUniswapV2Router02 uniswap = IUniswapV2Router02(ExchangeContract);
        srcToken.approve(address(uniswap), amount);
        address[] memory path = new address[](2);
        path[0] = address(srcToken);
        path[1] = address(dstToken);
        uint[] memory minOuts = uniswap.getAmountsOut(amount, path);
        uniswap.swapExactTokensForTokens(
          amount,
          minOuts[0],
          path,
          address(this),
          block.timestamp+15
        );
        return dstToken.balanceOf(address(this));
    }
1
  • What is the code? – Ismael Jan 18 at 4:03

Your Answer

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

Browse other questions tagged or ask your own question.