Skip to content

Instantly share code, notes, and snippets.

@az0mb13
Created June 2, 2022 10:07
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 az0mb13/13946d5c8cd1b2aa9f8df7de20d14835 to your computer and use it in GitHub Desktop.
Save az0mb13/13946d5c8cd1b2aa9f8df7de20d14835 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract EtherGame {
uint public targetAmount = 7 ether;
address public winner;
function deposit() public payable {
require(msg.value == 1 ether, "You can only send 1 Ether");
uint balance = address(this).balance;
require(balance <= targetAmount, "Game is over");
if (balance == targetAmount) {
winner = msg.sender;
}
}
function claimReward() public {
require(msg.sender == winner, "Not winner");
(bool sent, ) = msg.sender.call{value: address(this).balance}("");
require(sent, "Failed to send Ether");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment