Last active
April 10, 2018 16:32
-
-
Save JGcarv/9a73ec77cd28212e0c3dc20083eb3b4a 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.21; | |
import "./Utils/SafeMath.sol"; | |
contract ExampleToken{ | |
using SafeMath for uint256; | |
event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
event Approval(address indexed _owner, address indexed _spender, uint256 _value); | |
event Burn(address indexed _owner, uint256 _amount); | |
mapping (address => uint256) balances; | |
mapping (address => mapping (address => uint256)) allowed; | |
function transfer(address _to, uint256 _value) | |
public | |
returns (bool success) | |
{ | |
require(_to != address(0)); | |
require(_value <= balances[msg.sender]); | |
balances[msg.sender] = balances[msg.sender].add(_value); | |
balances[_to] = balances[_to].sub(_value); | |
Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
function transferFrom | |
(address _from, | |
address _to, | |
uint256 _value) | |
public | |
returns (bool success) { | |
require(_to != address(0)); | |
require(_value <= balances[_from]); | |
require(_value <= allowed[_from][msg.sender]); | |
balances[_from] = balances[_from].add(_value); | |
balances[_to] = balances[_to].sub(_value); | |
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); | |
Transfer(_from, _to, _value); | |
return true; | |
} | |
function approve(address _spender, uint256 _value) | |
public | |
onlyWhenTransferable | |
returns (bool success) | |
{ | |
allowed[msg.sender][_spender] = _value; | |
Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
function balanceOf(address _owner) view public returns (uint256 balance) { | |
return balances[_owner]; | |
} | |
function allowance(address _owner, address _spender) | |
view | |
public | |
returns (uint256 remaining) | |
{ | |
return allowed[_owner][_spender]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment