Skip to content

Instantly share code, notes, and snippets.

@aunyks
Last active January 26, 2018 12:06
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/09b2bfb2b919527e4601aefb5dd5fdd3 to your computer and use it in GitHub Desktop.
Save aunyks/09b2bfb2b919527e4601aefb5dd5fdd3 to your computer and use it in GitHub Desktop.
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;
}
}
}
@murphyjohn
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment