Created
June 2, 2022 10:07
-
-
Save az0mb13/13946d5c8cd1b2aa9f8df7de20d14835 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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