Skip to content

Instantly share code, notes, and snippets.

@mattlockyer
Created June 6, 2018 17:56
Show Gist options
  • Save mattlockyer/310cecd2322518786fab08fddf97b3ce to your computer and use it in GitHub Desktop.
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)
//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