Skip to main content
5 of 5
added 270 characters in body
Wyctus
  • 226
  • 2
  • 7

If you check the IERC20.approve() function's signature, you can see, that the first argument is the address that you allow to spend your DAI.

You used daiToken.approve(address(this), daiAmountIn) which means you allowed your contract to spend the DAI of your contract. This makes not much sense.

If you simply want to add some token to your contract from your own funds, you can transfer with your wallet to your contract's address. In this case just send some DAI to the contract's address.

If you would like to spend the caller's DAI tokens, then you have to allow it first. But of course the contract can't allow itself to spend others funds. You can go to etherscan to the DAI token's contract and call the approve() here with your contract's address. After that you will be able to call transferFrom() from your contract successfully up to the allowed amount.

Wyctus
  • 226
  • 2
  • 7