Created
February 14, 2018 18:54
-
-
Save ajb413/491f2e9d586dbcdaa6ebbc9653d7a371 to your computer and use it in GitHub Desktop.
An ERC-20 Ethereum 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; | |
import 'zeppelin-solidity/contracts/math/SafeMath.sol'; | |
/** | |
* Token | |
* | |
* @title A fixed supply ERC20 token contract. | |
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md | |
*/ | |
contract Token { | |
using SafeMath for uint; | |
event Transfer( | |
address indexed _from, | |
address indexed _to, | |
uint256 _value | |
); | |
event Approval( | |
address indexed _owner, | |
address indexed _spender, | |
uint256 _value | |
); | |
string public symbol; | |
string public name; | |
uint8 public decimals; | |
uint public totalSupply; | |
mapping(address => uint) balances; | |
mapping(address => mapping(address => uint)) allowed; | |
/** | |
* Constructs the Token contract and gives all of the supply to the address | |
* that deployed it. The fixed supply is 1 billion tokens with up to 18 | |
* decimal places. | |
*/ | |
function Token() public { | |
symbol = 'TOK'; | |
name = 'Token'; | |
decimals = 18; | |
totalSupply = 1000000000 * 10**uint(decimals); | |
balances[msg.sender] = totalSupply; | |
Transfer(address(0), msg.sender, totalSupply); | |
} | |
/** | |
* @dev Fallback function | |
*/ | |
function() public payable { revert(); } | |
/** | |
* Gets the token balance of any wallet. | |
* @param _owner Wallet address of the returned token balance. | |
* @return The balance of tokens in the wallet. | |
*/ | |
function balanceOf(address _owner) | |
public | |
constant | |
returns (uint balance) | |
{ | |
return balances[_owner]; | |
} | |
/** | |
* Transfers tokens from the sender's wallet to the specified `_to` wallet. | |
* @param _to Address of the transfer's recipient. | |
* @param _value Number of tokens to transfer. | |
* @return True if the transfer succeeded, false if not. | |
*/ | |
function transfer(address _to, uint _value) public returns (bool success) { | |
balances[msg.sender] = balances[msg.sender].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
/** | |
* Transfer tokens from any wallet to the `_to` wallet. This only works if | |
* the `_from` wallet has already allocated tokens for the caller keyset | |
* using `approve`. From wallet must have sufficient balance to | |
* transfer. Caller must have sufficient allowance to transfer. | |
* @param _from Wallet address that tokens are withdrawn from. | |
* @param _to Wallet address that tokens are deposited to. | |
* @param _value Number of tokens transacted. | |
* @return True if the transfer succeeded, false if not. | |
*/ | |
function transferFrom(address _from, address _to, uint _value) | |
public | |
returns (bool success) | |
{ | |
balances[_from] = balances[_from].sub(_value); | |
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
Transfer(_from, _to, _value); | |
return true; | |
} | |
/** | |
* Sender allows another wallet to `transferFrom` tokens from their wallet. | |
* @param _spender Address of `transferFrom` recipient. | |
* @param _value Number of tokens to `transferFrom`. | |
* @return True if the approval succeeded, false if not. | |
*/ | |
function approve(address _spender, uint _value) | |
public | |
returns (bool success) | |
{ | |
allowed[msg.sender][_spender] = _value; | |
Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
/** | |
* Gets the number of tokens that a `_owner` has approved for a _spender | |
* to `transferFrom`. | |
* @param _owner Wallet address that tokens can be withdrawn from. | |
* @param _spender Wallet address that tokens can be deposited to. | |
* @return The number of tokens allowed to be transferred. | |
*/ | |
function allowance(address _owner, address _spender) | |
public | |
constant | |
returns (uint remaining) | |
{ | |
return allowed[_owner][_spender]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment