Last active
October 4, 2018 21:47
-
-
Save zastrin/da73622f228c8ff97f87933f77d97f98 to your computer and use it in GitHub Desktop.
Super basic 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.24; | |
contract ERC20Token { | |
uint public supply = 1000000; | |
uint public price = 0.001 ether; | |
string public name = "Hackathon Token"; | |
string public symbol = "HKT"; | |
uint public decimals = 18; | |
address public owner; | |
mapping(address => uint256) balances; | |
constructor() public { | |
owner = msg.sender; | |
balances[msg.sender] = supply * 10 ** decimals; | |
} | |
function totalSupply() public constant returns (uint) { | |
return supply; | |
} | |
function balanceOf(address tokenOwner) public view returns (uint balance) { | |
return balances[tokenOwner]; | |
} | |
function transfer(address to, uint tokens) public returns (bool success) { | |
// decrement the balance from msg.sender | |
// increment token count for to | |
uint totalTokens = tokens * 10 ** decimals; | |
require(totalTokens <= balances[msg.sender]); | |
require(to != address(0)); | |
balances[msg.sender] = balances[msg.sender] - totalTokens; | |
balances[to] = balances[to] + totalTokens; | |
return true; | |
} | |
function purchase() public payable { | |
uint tokens = msg.value/price; | |
uint totalTokens = tokens * 10 ** decimals; | |
require(totalTokens <= balances[owner]); | |
balances[owner] = balances[owner] - totalTokens; | |
balances[msg.sender] = balances[msg.sender] + totalTokens; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment