I have these functions and deployed my contract to Ropsten testnet.
function setSmartContractAllownace(uint daiAmountIn) public {
IERC20 daiToken = IERC20(ropstenDAI);
daiToken.approve(address(this), daiAmountIn);
}
function getContractAddress() public view returns (address) {
return address(this);
}
function getOwner() public view returns (address) {
return msg.sender;
}
When I call getContractAddress()
and getOwner()
, they return the correct values respectively.
However, when I call setSmartContractAllownace(1000)
, it successfully approves, but the caller (owner) is set to the address of the smart contract.
I verified this by going into DAI and checking the allowance.
This is when I put my account with DAI as _owner
and smart contract as _spender
As you can see, this returns 0.
But if I put _owner
also as smart contract,
it shows the correct allowance.
What is going on?
Thank you.
someToken.approve(address(this), someAmount)
is meaningless, as you are only approving the contract to transfer tokens from itself (i.e., you can now calltransferFrom
inside this contract, but heck, you may as well just calltransfer
without any approval, and get the exact same result).