Created
June 6, 2018 17:53
-
-
Save mattlockyer/d7068dcfa2e90eea9fa36b0900d0ff30 to your computer and use it in GitHub Desktop.
HelloMarket smart contract for Solidity workshops
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 HelloMarket is Owner { | |
uint256 public price; | |
string public message; | |
constructor() public { | |
owner = msg.sender; | |
} | |
event Talk(string _message, address _from); | |
function talk(string _message) public onlyOwner { | |
message = _message; | |
emit Talk(_message, msg.sender); | |
} | |
function buyRights() payable public returns (bool) { | |
if (msg.value > price) { | |
owner = msg.sender; | |
price = msg.value; | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment