Skip to content

Instantly share code, notes, and snippets.

@naoyamakino
Created January 15, 2018 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naoyamakino/d22474d08e5dd48e640df775fb3adbef to your computer and use it in GitHub Desktop.
Save naoyamakino/d22474d08e5dd48e640df775fb3adbef to your computer and use it in GitHub Desktop.
My first smart contract!
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;
}
}
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