Last active
January 26, 2018 12:06
-
-
Save aunyks/09b2bfb2b919527e4601aefb5dd5fdd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract MyERCToken { | |
mapping(address => uint256) balances; | |
function transferFrom(address _from, address _to, uint256 _amount) returns (bool success) { | |
if (balances[_from] >= _amount | |
&& allowed[_from][msg.sender] >= _amount | |
&& _amount > 0 | |
&& balances[_to] + _amount > balances[_to]) { | |
balances[_from] -= _amount; | |
balances[_to] += _amount; | |
Transfer(_from, _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
Hi,
Why do we need both transfer() and transferFrom() functions?
I see in your medium article you mention it being a means to have "a contract can send a certain amount of the token to another address on your behalf, without your intervention.", but how does this work in practice?
Don't I have to call the transferFrom function just like I would call the transfer function?
What exactly would be the use case and how with this be implemented. I am struggling with your paying bills example.
I appreciate any help you can give and thank you for the article and code segments.