Lets assume situation is this. I have a contract where there are some ERC20 tokens are stored. And there are some whitelisted addresses. I want those addresses to be able to withdraw tokens to their addresses.
example code:
pragma solidity ^0.4.0;
contract TokenInterface {
function transfer(address _from, address _to, uint _value) returns (bool success);
}
contract Example contract {
...
TokenInterface private _instance;
function claimTokens () public onlyWhitelisted returns (bool){
require(!_investors[msg.sender].claimed);
uint tokensToBeClaimed = _investors[msg.sender].invested * ratio;
if(_instance.transfer(contractAddress, msg.sender, tokensToBeClaimed)){
_investors[msg.sender].claimed = true;
return true;
} else {
_investors[msg.sender].claimed = false;
return false;
}
}
....
}
Its not full code, but main thing is here. I am sure this is not the way to do it, and maybe someone will help me?
EDIT.
I've found this line of code.
contract TokenInterface {
function transferFrom(address from, address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
}
and then in claimTokens function:
_instance.approve(msg.sender, tokensToBeClaimed);
_instance.transferFrom(contractAddress, msg.sender, tokensToBeClaimed)
can someone approve?