Created
July 26, 2018 18:03
-
-
Save fiksn/f183ab5f37154894aefed6e71adf5cb0 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
// latest version https://github.com/ethereum/solidity/releases 0.4.24 | |
pragma solidity ^0.4.24; | |
contract ERC20 { | |
//string public constant name = "Token Name"; | |
//string public constant symbol = "SYM"; | |
//uint8 public constant decimals = 18; | |
function totalSupply() public constant returns (uint256); | |
function balanceOf(address _owner) public constant returns (uint256); | |
function transfer(address _to, uint256 _value) public returns (bool); | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool); | |
function approve(address _spender, uint256 _value) public returns (bool); | |
function allowance(address _owner, address _spender) public constant returns (uint256); | |
event Approval(address indexed _owner, address indexed _spender, uint256 _value); | |
event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
} | |
library SafeMath { | |
function mul(uint256 a, uint256 b) internal pure returns (uint256) { | |
uint256 c = a * b; | |
assert(a == 0 || c / a == b); | |
return c; | |
} | |
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 c; | |
} | |
function sub(uint256 a, uint256 b) internal pure returns (uint256) { | |
assert(b <= a); | |
return a - b; | |
} | |
function add(uint256 a, uint256 b) internal pure returns (uint256) { | |
uint256 c = a + b; | |
assert(c >= a); | |
return c; | |
} | |
} | |
contract Owned { | |
address public owner; | |
address public newOwner; | |
event OwnershipTransferred(address indexed _from, address indexed _to); | |
constructor() public { | |
owner = msg.sender; | |
} | |
modifier onlyOwner { | |
require(msg.sender == owner); | |
_; | |
} | |
function transferOwnership(address _newOwner) public onlyOwner { | |
newOwner = _newOwner; | |
} | |
function acceptOwnership() public { | |
require(msg.sender == newOwner); | |
emit OwnershipTransferred(owner, newOwner); | |
owner = newOwner; | |
newOwner = address(0); | |
} | |
} | |
contract ExampleToken is ERC20, Owned { | |
using SafeMath for uint256; | |
string public name; | |
string public symbol; | |
uint8 public decimals; | |
uint256 supply; | |
mapping (address => uint256) balances; | |
mapping (address => mapping(address => uint256)) allowances; | |
constructor() public { | |
symbol = "EXAMPLE"; | |
name = "Example token"; | |
decimals = 18; | |
supply = 21000000 * 10**uint(decimals); | |
balances[owner] = supply; | |
emit Transfer(address(0), owner, supply); | |
} | |
function totalSupply() constant public returns (uint256) { | |
return supply; | |
} | |
function allowance(address _owner, address _spender) public constant | |
returns (uint256 remaining) { | |
return allowances[_owner][_spender]; | |
} | |
function balanceOf(address _owner) constant returns (uint256 balance) { | |
return balances[_owner]; | |
} | |
function transfer(address _to, uint256 _value) public returns (bool success) { | |
require(_value <= balances[msg.sender]); | |
//require(_to != address(0)); | |
// SafeMath.sub will throw if there is not enough balance. | |
balances[msg.sender] = balances[msg.sender].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
emit Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
function approve(address _spender, uint256 _value) returns (bool success) { | |
allowances[msg.sender][_spender] = _value; | |
emit Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
function transferFrom(address _from, address _to, uint256 _value) | |
returns (bool success) { | |
require(_to != address(0)); | |
require(_value <= balances[_from]); | |
require(_value <= allowances[_from][msg.sender]); | |
balances[_from] = balances[_from].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
allowances[_from][msg.sender] = allowances[_from][msg.sender].sub(_value); | |
emit Transfer(_from, _to, _value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment