Created
January 22, 2018 10:21
-
-
Save goastoman/ec1e61eae92837bf14865d1922b5027e to your computer and use it in GitHub Desktop.
Simple Coin Token
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.18; | |
contract Ownable { | |
address public owner; | |
function Ownable() public { | |
owner = msg.sender; | |
} | |
modifier onlyOwner() { | |
require(msg.sender == owner); | |
_; | |
} | |
function transferOwnership(address newOwner) public onlyOwner { | |
owner = newOwner; | |
} | |
} | |
contract SimpleTokenCoin is Ownable { | |
string public constant name = "Simple Coin Token"; | |
string public constant symbol = "SCT"; | |
uint32 public constant decimals = 18; | |
uint public totalSupply = 0; | |
mapping (address => uint) balances; | |
mapping (address => mapping(address => uint)) allowed; | |
function mint(address _to, uint _value) public onlyOwner { | |
assert(totalSupply + _value >= totalSupply && balances[_to] + _value >= balances[_to]); | |
balances[_to] += _value; | |
totalSupply += _value; | |
} | |
function balanceOf(address _owner) public constant returns (uint balance) { | |
return balances[_owner]; | |
} | |
function transfer(address _to, uint _value) public returns (bool success) { | |
if(balances[msg.sender] >= _value && balances[_to] + _value >= balances[_to]) { | |
balances[msg.sender] -= _value; | |
balances[_to] += _value; | |
Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
return false; | |
} | |
function transferFrom(address _from, address _to, uint _value) public returns (bool success) { | |
if( allowed[_from][msg.sender] >= _value && | |
balances[_from] >= _value | |
&& balances[_to] + _value >= balances[_to]) { | |
allowed[_from][msg.sender] -= _value; | |
balances[_from] -= _value; | |
balances[_to] += _value; | |
Transfer(_from, _to, _value); | |
return true; | |
} | |
return false; | |
} | |
function approve(address _spender, uint _value) public returns (bool success) { | |
allowed[msg.sender][_spender] = _value; | |
Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
function allowance(address _owner, address _spender) public constant returns (uint remaining) { | |
return allowed[_owner][_spender]; | |
} | |
event Transfer(address indexed _from, address indexed _to, uint _value); | |
event Approval(address indexed _owner, address indexed _spender, uint _value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment