After deploying ERC20
contract (MyToken
), I transferred all tokens to MyToken
contract.
Then I deployed a service contract that has one method called claimWining()
which is supposed to transfer tokens to a caller account from MyToken
contract.
pragma solidity ^0.5.0;
contract MyToken is Context, ERC20, ERC20Detailed {
constructor () public ERC20Detailed("DEST", "DST", 18) {
_mint(_msgSender(), 1000000000 * (10 ** uint256(decimals())));
}
}
contract Claim {
MyToken public token;
address myToken;
constructor(address _tokenAddress) public {
token = MyToken(_tokenAddress);
myToken= _tokenAddress;
}
function claimWinning() public {
// doesn't work
token.transferFrom(myToken, msg.sender, 100000);
}
}
Here I used transferFrom()
, but it was not working because I was unable to execute approve()
initially.
function approve(address spender, uint256 amount) public returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
I found that MyToken
contract itself should call approve()
as msg.sender
, but I'm not sure how to do it.
Basically, what I want is platform user calls claimWinning()
to get rewarded with ERC20
token.
How can users receive tokens from MyToken
contract?
MyToken
contract". This contract doesn't have any tokens by itself.