Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Created May 13, 2021 19:36
Show Gist options
  • Save percybolmer/e2a1665bdd2969c50e90c3b2e8ab6977 to your computer and use it in GitHub Desktop.
Save percybolmer/e2a1665bdd2969c50e90c3b2e8ab6977 to your computer and use it in GitHub Desktop.
/**
* @notice transfer is used to transfer funds from the sender to the recipient
* This function is only callable from outside the contract. For internal usage see
* _transfer
*
* Requires
* - Caller cannot be zero
* - Caller must have a balance = or bigger than amount
*
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @notice _transfer is used for internal transfers
*
* Events
* - Transfer
*
* Requires
* - Sender cannot be zero
* - recipient cannot be zero
* - sender balance most be = or bigger than amount
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "DevToken: transfer from zero address");
require(recipient != address(0), "DevToken: transfer to zero address");
require(_balances[sender] >= amount, "DevToken: cant transfer more than your account holds");
_balances[sender] = _balances[sender] - amount;
_balances[recipient] = _balances[recipient] + amount;
emit Transfer(sender, recipient, amount);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment