Created
December 4, 2018 07:39
-
-
Save sherlock-shi-x/9b04842bc176c50ded88571590c5976b to your computer and use it in GitHub Desktop.
StandardToken.sol
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.5.1; | |
contract ERC20 { | |
function transfer(address _to, uint256 _value) public returns (bool success); | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); | |
function approve(address _spender, uint256 _value) public returns (bool success); | |
event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
event Approval(address indexed _owner, address indexed _spender, uint256 _value); | |
} | |
contract BlockMiracleToken is ERC20 { | |
string public name = "BlockMiracleToken"; | |
string public symbol = "BMT"; | |
uint8 public decimals = 10; | |
uint256 public totalSupply = 100000000000000000000; | |
using SafeMath for uint256; | |
mapping (address => uint256) public balanceOf; | |
mapping (address => mapping (address => uint256)) public allowance; | |
constructor() public { | |
balanceOf[msg.sender] = totalSupply; | |
} | |
function transfer(address _to, uint256 _value) public returns (bool success) { | |
require (_to != address(0x0) && _value > 0); | |
require (balanceOf[msg.sender] >= _value); | |
balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); | |
balanceOf[_to] = balanceOf[_to].add(_value); | |
emit Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
function approve(address _spender, uint256 _value) public returns (bool success) { | |
require (_value > 0); | |
allowance[msg.sender][_spender] = _value; | |
emit Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { | |
require (_to != address(0x0) && _value > 0); | |
require (balanceOf[_from] >= _value && _value <= allowance[_from][msg.sender]); | |
balanceOf[_from] = balanceOf[_from].sub(_value); | |
balanceOf[_to] = balanceOf[_to].add(_value); | |
allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); | |
emit Transfer(_from, _to, _value); | |
return true; | |
} | |
} | |
/** | |
* @title SafeMath | |
* @dev Math operations with safety checks that throw on error | |
*/ | |
library SafeMath { | |
/** | |
* @dev Multiplies two numbers, throws on overflow. | |
*/ | |
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { | |
if (a == 0) { | |
return 0; | |
} | |
c = a * b; | |
assert(c / a == b); | |
return c; | |
} | |
/** | |
* @dev Integer division of two numbers, truncating the quotient. | |
*/ | |
function div(uint256 a, uint256 b) internal pure returns (uint256) { | |
// assert(b > 0); // Solidity automatically throws when dividing by 0 | |
// uint256 c = a / b; | |
// assert(a == b * c + a % b); // There is no case in which this doesn't hold | |
return a / b; | |
} | |
/** | |
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). | |
*/ | |
function sub(uint256 a, uint256 b) internal pure returns (uint256) { | |
assert(b <= a); | |
return a - b; | |
} | |
/** | |
* @dev Adds two numbers, throws on overflow. | |
*/ | |
function add(uint256 a, uint256 b) internal pure returns (uint256 c) { | |
c = a + b; | |
assert(c >= a); | |
return c; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment