Using Solidity, how can I transfer ERC20 tokens from the current address to another?
Is it done using call or send? Are the balances kept in the token contract or in the address that the tokens belong to?
ERC20 Token contracts store the balances of users in its state. The exact specification of the ERC20 token contracts can be found here: https://theethereum.wiki/w/index.php/ERC20_Token_Standard
transferFrom function can be used to transfer tokens from one address to another.
function transferFrom(address _from, address _to, uint _value) returns (bool success);
This function has to be called as a transaction in order to make changes in the balance (i.e. state of the contract). The difference between a
call and a
transaction is detailed here.
What is the difference between a transaction and a call?
To transfer EIP20 Token from another contract, use
EIP20 token = EIP20(_tokenAddr);
and call tansferFrom function to transfer tokens from one address to another; like;
token.transferFrom(msg.sender, this, _value);
Note: Before you do this, do call the approve function on the Token Contract to allow
this contract to use tokens on your (or msg.sender) behalf.