Created
June 6, 2018 17:56
-
-
Save mattlockyer/310cecd2322518786fab08fddf97b3ce to your computer and use it in GitHub Desktop.
HelloMarket smart contract example with a token for Solidity tutorials (not ERC-20 compliant)
This file contains hidden or 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
//jshint ignore: start | |
pragma solidity ^0.4.21; | |
contract Owner { | |
address public owner; | |
modifier onlyOwner() { | |
require(msg.sender == owner); | |
_; | |
} | |
function transferOwnership(address _to) public onlyOwner { | |
owner = _to; | |
} | |
} | |
contract SimpleToken is Owner { | |
uint256 public totalSupply; | |
mapping(address => uint256) public balances; | |
//token functions | |
function mint(address _to, uint256 _amount) public onlyOwner returns (bool) { | |
totalSupply += _amount; | |
balances[_to] += _amount; | |
return true; | |
} | |
function transfer(address _to, uint256 _amount) public returns (bool) { | |
require(balances[msg.sender] >= _amount); | |
balances[msg.sender] -= _amount; | |
balances[_to] += _amount; | |
return true; | |
} | |
} | |
contract HelloMarketToken is SimpleToken { | |
string public message; | |
//token data | |
uint256 public talkFund; | |
//hello market functions | |
constructor() public { | |
owner = msg.sender; | |
} | |
event Talk(string _message, address _from); | |
//modified talk function | |
function talk(string _message) public { | |
require(balances[msg.sender] >= 100); | |
balances[msg.sender] -= 100; | |
talkFund += 100; | |
message = _message; | |
emit Talk(_message, msg.sender); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment