Last active
May 14, 2018 06:37
-
-
Save Roger-Wu/da54896c26d8fa0ac921725c58f51624 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.4.23; | |
contract SimpleToken { | |
string public name = "SimpleToken"; | |
string public symbol = "SMPT"; | |
uint8 public decimals = 18; | |
uint256 public totalSupply = 1e24; | |
mapping (address => uint256) public balanceOf; | |
mapping (address => mapping (address => uint256)) public allowance; | |
event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
event Approval(address indexed _owner, address indexed _spender, uint256 _value); | |
constructor() public { | |
balanceOf[msg.sender] = totalSupply; | |
emit Transfer(0, msg.sender, totalSupply); | |
} | |
function transfer(address _to, uint256 _value) external returns (bool success) { | |
_transfer(msg.sender, _to, _value); | |
return true; | |
} | |
function transferFrom(address _from, address _to, uint256 _value) external returns (bool success) { | |
require(allowance[_from][msg.sender] >= _value); | |
_transfer(_from, _to, _value); | |
allowance[_from][msg.sender] -= _value; | |
return true; | |
} | |
function approve(address _spender, uint256 _value) external returns (bool success) { | |
allowance[msg.sender][_spender] = _value; | |
emit Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
function _transfer(address _from, address _to, uint256 _value) private { | |
require(balanceOf[_from] >= _value); | |
balanceOf[_from] -= _value; | |
balanceOf[_to] += _value; | |
emit Transfer(_from, _to, _value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment