Last active
September 30, 2017 20:28
-
-
Save TheBojda/3769cebbf0268558cfd0ed16e5dc977e 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.8; | |
contract Token { | |
string public constant symbol = "TST"; | |
string public constant name = "Test token"; | |
uint8 public constant decimals = 18; | |
event Transfer(address indexed from, address indexed to, uint value); | |
event Approval( address indexed owner, address indexed spender, uint value); | |
mapping( address => uint ) _balances; | |
mapping( address => mapping( address => uint ) ) _approvals; | |
uint public _supply = 1000000; | |
function Token() { | |
_balances[msg.sender] = _supply; | |
} | |
function totalSupply() constant returns (uint supply) { | |
return _supply; | |
} | |
function balanceOf( address who ) constant returns (uint value) { | |
return _balances[who]; | |
} | |
function transfer( address to, uint value) returns (bool ok) { | |
if( _balances[msg.sender] < value ) { | |
throw; | |
} | |
if( !safeToAdd(_balances[to], value) ) { | |
throw; | |
} | |
_balances[msg.sender] -= value; | |
_balances[to] += value; | |
Transfer( msg.sender, to, value ); | |
return true; | |
} | |
function transferFrom( address from, address to, uint value) returns (bool ok) { | |
if( _balances[from] < value ) { | |
throw; | |
} | |
if( _approvals[from][msg.sender] < value ) { | |
throw; | |
} | |
if( !safeToAdd(_balances[to], value) ) { | |
throw; | |
} | |
_approvals[from][msg.sender] -= value; | |
_balances[from] -= value; | |
_balances[to] += value; | |
Transfer( from, to, value ); | |
return true; | |
} | |
function approve(address spender, uint value) returns (bool ok) { | |
_approvals[msg.sender][spender] = value; | |
Approval( msg.sender, spender, value ); | |
return true; | |
} | |
function allowance(address owner, address spender) constant returns (uint _allowance) { | |
return _approvals[owner][spender]; | |
} | |
function safeToAdd(uint a, uint b) internal returns (bool) { | |
return (a + b >= a); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment