Skip to content

Instantly share code, notes, and snippets.

@xd4rker
Created April 16, 2018 11:52
Show Gist options
  • Save xd4rker/0761c77f85523da574680ff995e002c4 to your computer and use it in GitHub Desktop.
Save xd4rker/0761c77f85523da574680ff995e002c4 to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.21;
contract GuessTheNewNumberChallenge {
function GuessTheNewNumberChallenge() public payable {
require(msg.value == 1 ether);
}
function isComplete() public view returns (bool) {
return address(this).balance == 0;
}
function guess(uint8 n) public payable {
require(msg.value == 1 ether);
uint8 answer = uint8(keccak256(block.blockhash(block.number - 1), now));
if (n == answer) {
msg.sender.transfer(2 ether);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment