Created
January 15, 2018 04:36
-
-
Save naoyamakino/d22474d08e5dd48e640df775fb3adbef to your computer and use it in GitHub Desktop.
My first smart contract!
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; | |
contract Addition { | |
uint sum; | |
function Addition() payable public { | |
} | |
function () payable public { | |
} | |
function add(uint _one, uint _two) public { | |
sum = _one + _two; | |
} | |
function getSum() public view returns (uint) { | |
return sum; | |
} | |
} |
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; | |
contract GuessMonth { | |
uint month; | |
uint oneEther = 1000000000000000; | |
address owner; | |
event GuessMade(string correctOrNot); // Event | |
event MonthChanged(string textToLog); // Event | |
modifier onlyOwner() { | |
if (msg.sender != owner) { | |
revert(); | |
} | |
_; | |
} | |
function GuessMonth (uint _month) payable public { | |
month = _month; | |
owner = msg.sender; | |
} | |
function sendGuess(uint _guess) payable public { | |
if (month == _guess) { | |
GuessMade("Correct!"); | |
msg.sender.transfer(2 * oneEther); | |
} else { | |
GuessMade("Incorrect!"); | |
} | |
} | |
function chnageMonth(uint _newMonth) onlyOwner public { | |
month = _newMonth; | |
} | |
function getMonth() public view returns(uint) { | |
return month; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment