Transferring tokens between accounts
Tokens can be transferred between multiple accounts. This allows you to trade tokens in exchange for services. To achieve this functionality, ERC20 provides a standard function definition. You will learn to implement basic transfer function with this recipe.
Getting ready
You need to have a development environment that supports solidity programming and an Ethereum network to deploy and test your code.
How to do it...
- ERC20 defines a
transfer
function to transfer tokens between accounts. Create the function to implement the feature:
function transfer() { }
- Modify the function to accept two parameters: to address the amount to transfer. It should return a result of type
boolean
to indicate success or failure:
function transfer(address_to, uint256_value) publicreturns (bool) { }
- Use the
msg.sender
property to determine the from address. You don't have to explicitly pass the from address. The function considers the address of the transaction sender as the from...