# Predict the Future
To properly lock you in, unlike the blockhash challenge, we decided to add the block's timestamp to the settlement.
Ah, don't forget to withdraw the money back to your account!
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.11;
contract PredictTheFuture {
address guesser;
uint8 guess;
uint256 settlementBlockNumber;
constructor(address _player) payable {
require(msg.value == 1 gwei);
require(_player != address(0));
}
function solved() public view returns (bool) {
return address(this).balance == 0;
}
function lockInGuess(uint8 n) public payable {
require(guesser == address(0));
require(msg.value == 1 gwei);
guesser = msg.sender;
guess = n;
settlementBlockNumber = block.number + 1;
}
function settle() public {
require(msg.sender == guesser);
require(block.number > settlementBlockNumber);
uint8 answer = uint8(uint(keccak256(
abi.encodePacked(blockhash(block.number - 1), block.timestamp)))) % 10;
guesser = address(0);
if (guess == answer) {
payable(msg.sender).transfer(2 gwei);
}
}
}