Skip to content

Instantly share code, notes, and snippets.

@muellerberndt
Created March 25, 2019 05:17
Show Gist options
  • Select an option

  • Save muellerberndt/e0a91db1645ab5cb30fee11d7bd54e0f to your computer and use it in GitHub Desktop.

Select an option

Save muellerberndt/e0a91db1645ab5cb30fee11d7bd54e0f to your computer and use it in GitHub Desktop.
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
* @source: https://capturetheether.com/challenges/lotteries/guess-the-random-number/
* @author: Steve Marx
*/
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