3

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?

6

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

The 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?

1

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.

approve(this, _amount)
  • How to call approve from the senders' address? – CryptoScroller Jan 22 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.