Created
January 17, 2023 23:32
-
-
Save Jesserc/24deb7573902fd589a659ec100d07f1d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| contract BidderTwo { | |
| uint256 highestBid; | |
| address currentHighestBidder; | |
| mapping(address => uint) bidBalances; | |
| function bid() external payable { | |
| require(msg.value > highestBid, "Bid higher"); | |
| bidBalances[msg.sender] += msg.value; | |
| highestBid = msg.value; | |
| currentHighestBidder = msg.sender; | |
| } | |
| function withdraw() external { | |
| require(msg.sender == currentHighestBidder, "Not highest bidder"); | |
| payable(currentHighestBidder).transfer(highestBid); | |
| } | |
| function withdrawLessBid() external { | |
| require( | |
| msg.sender != currentHighestBidder, | |
| "Highest Bidder can't withdraw" | |
| ); | |
| uint256 balance = bidBalances[msg.sender]; | |
| require(balance > 0, "No bid amount"); | |
| payable(msg.sender).transfer(balance); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment