Skip to content

Instantly share code, notes, and snippets.

@aunyks
Last active August 17, 2017 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aunyks/6bfaef246d3f1bbe30020249e0c28e2e to your computer and use it in GitHub Desktop.
Save aunyks/6bfaef246d3f1bbe30020249e0c28e2e to your computer and use it in GitHub Desktop.
contract MyERCToken {
mapping(address => uint256) balances;
// Note: This function returns a boolean value
// indicating whether the transfer was successful
function transfer(address _to, uint256 _amount) returns (bool success) {
// If the sender has sufficient funds to send
// and the amount is not zero, then send to
// the given address
if (balances[msg.sender] >= _amount
&& _amount > 0
&& balances[_to] + _amount > balances[_to]) {
balances[msg.sender] -= _amount;
balances[_to] += _amount;
// Fire a transfer event for any
// logic that's listening
Transfer(msg.sender, _to, _amount);
return true;
} else {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment