Last active
April 8, 2018 08:11
-
-
Save beenhero/ad8fb2f596174ff3dbdb8312e63b454a to your computer and use it in GitHub Desktop.
ERC20-StandardToken
This file contains hidden or 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.18; | |
import "./Token.sol"; | |
import "./Math.sol"; | |
contract ERC20 is Token { | |
using Math for *; | |
mapping (address => uint) balances; | |
mapping (address => mapping (address => uint)) allowances; | |
uint totalTokens; | |
function transfer(address to, uint value) | |
public | |
returns (bool) | |
{ | |
if ( !balances[msg.sender].safeToSub(value) | |
|| !balances[to].safeToAdd(value)) | |
return false; | |
balances[msg.sender] -= value; | |
balances[to] += value; | |
Transfer(msg.sender, to, value); | |
return true; | |
} | |
function transferFrom(address from, address to, uint value) | |
public | |
returns (bool) | |
{ | |
if ( !balances[from].safeToSub(value) | |
|| !allowances[from][msg.sender].safeToSub(value) | |
|| !balances[to].safeToAdd(value)) | |
return false; | |
balances[from] -= value; | |
allowances[from][msg.sender] -= value; | |
balances[to] += value; | |
Transfer(from, to, value); | |
return true; | |
} | |
function approve(address spender, uint value) | |
public | |
returns (bool) | |
{ | |
allowances[msg.sender][spender] = value; | |
Approval(msg.sender, spender, value); | |
return true; | |
} | |
function allowance(address owner, address spender) | |
public | |
constant | |
returns (uint) | |
{ | |
return allowances[owner][spender]; | |
} | |
function balanceOf(address owner) | |
public | |
constant | |
returns (uint) | |
{ | |
return balances[owner]; | |
} | |
function totalSupply() | |
public | |
constant | |
returns (uint) | |
{ | |
return totalTokens; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment