Skip to content

Instantly share code, notes, and snippets.

@xd4rker
Created April 15, 2018 09:37
Show Gist options
  • Save xd4rker/d170d63fbe306427d9e3aff1281b430c to your computer and use it in GitHub Desktop.
Save xd4rker/d170d63fbe306427d9e3aff1281b430c to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.21;
contract GuessTheRandomNumberChallenge {
uint8 answer;
function GuessTheRandomNumberChallenge() public payable {
require(msg.value == 1 ether);
answer = uint8(keccak256(block.blockhash(block.number - 1), now));
}
function isComplete() public view returns (bool) {
return address(this).balance == 0;
}
function guess(uint8 n) public payable {
require(msg.value == 1 ether);
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