I'm using UniswapV2Router02 contract and here is the problem.
When I try to call the swap function in Remix IDE it shows me

execution reverted: Dai/insufficient-allowance

Although I have DAI in the account that I'm sending the transaction with.
Here is the full code Click on this link and copy paste the code in your Remix IDE (Ignore the additional files if you're not familiar with codesandbox just the opened file code will be enough :) )


and here is the values that i'm passing to swap function (since I'm using Remix tools to do it, I'm just assigning them here so that it's more clear)

_tokenIn: 0xc7AD46e0b8a400Bb3C915120d284AafbA8fc4735
_tokenOut: 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984
_amountIn: 100000
_minAmountOut: 0000001// I guess I’m doing something wrong here please let me know if it's wrong
_to: 0x9b6582f3b8c262B062BDC779064F16aB026eE566// the account that i'm sure has DAI

I'm using Injected provider (MetaMask) for ENVIRONMENT

2 Answers 2


You need to call approve function. You need to approve DAI spender as contract address from your wallet account.

Here, spender is contract address

amount is _amountIn * 1e18

And you need to approve from your wallet account

Also remember, you have to send this transaction to DAI contract.

DAI.approve(spender, amount, {"from":account})

  • So I should not approve it in the contract, right?
    – Yaya
    Commented Jul 29, 2022 at 9:27
  • Therefore the I cannot do the transaction from Remix IDE since I cannot approve it outside of contract
    – Yaya
    Commented Jul 29, 2022 at 9:30
  • Ok so now when I call approve function outside of contract (in metamask) i get Fail with error UniswapV2Library: INSUFFICIENT_LIQUIDITY
    – Yaya
    Commented Jul 29, 2022 at 10:32
  • I'm trying to swap DAI for UNI
    – Yaya
    Commented Jul 29, 2022 at 10:33
  • approve never gives error like this. You must be doing something else, please share which transaction are you making. Note: you have to send transaction to DAI contract Commented Jul 31, 2022 at 12:38

You probably didn't approve the contract to spend your DAI, here's the method you need to call to fix it https://docs.openzeppelin.com/contracts/2.x/api/token/erc20#IERC20-approve-address-uint256-

Your Answer

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

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