This is my following Code. I am using the Rinkeby network.
//SPDX-License-Identifier: MIT
pragma solidity ^0.8;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol";
contract TransferDAI{
IERC20 public dai;
constructor() {
dai = IERC20(0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa);
}
function Transfer(uint _amount) external {
dai.transferFrom(msg.sender, address(this), _amount);
}
// Some extra functions for now...
function getDaiBalance(address _address) external view returns(uint) {
return dai.balanceOf(_address);
}
}
I am not able to transfer Dai to the contract address. Although I can view getDaiBalance
and see the correct amount of DAIs.
Any lead will be helpful. I tried using dai.approve(msg.sender,_amount)
it wasn't helpful.
Best Answer
dai.approve(msg.sender, _amount)
letsmsg.sender
spend_amount
of tokens that are in the contract balance. Not the other way around. You need to have your wallet callapprove
directly on the DAI contract address, with your contract address and amount as inputs.