Hello guys! I am trying to deposit kovan dai to my smart contract by using transferFrom of the ERC20 function. But I get an the ‘Dai/insufficient-allowance’.So I tried approving it explicitly and then trying to transfer… The approval works but this the transferFrom doesnt. Please help me. Just started with ERC 20.
The code:
function appDai(uint _amount) public {
daitoken.approve(msg.sender, _amount);
}
function depDai(uint _amount) public {
require(daitoken.balanceOf(msg.sender) >= _amount);
daitoken.transferFrom(msg.sender, address(this), _amount);
emit Deposit(msg.sender, _amount);
}