Created
April 20, 2020 12:36
-
-
Save agoiabel/8ac97b5da5154c0668f4614c9add129c 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
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