Skip to content

Instantly share code, notes, and snippets.

@agoiabel
Created April 20, 2020 12:36
Show Gist options
  • Save agoiabel/8ac97b5da5154c0668f4614c9add129c to your computer and use it in GitHub Desktop.
Save agoiabel/8ac97b5da5154c0668f4614c9add129c to your computer and use it in GitHub Desktop.
pragma solidity ^0.6.4;
contract Token {
...
...
mapping(address => uint) public balanceOf;
event Transfer(address indexed _from, address indexed _to, uint256 _value);
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
function transfer(address _to, uint _value) public returns (bool success) {
require(_to != address(0));
require(balanceOf[msg.sender] >= _value);
balanceOf[msg.sender] = sub(balanceOf[_to], _value);
balanceOf[_to] = add(balanceOf[_to], _value);
emit Transfer(msg.sender, _to, _value);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment