Skip to content

Instantly share code, notes, and snippets.

@Jesserc
Created January 17, 2023 23:32
Show Gist options
  • Select an option

  • Save Jesserc/24deb7573902fd589a659ec100d07f1d to your computer and use it in GitHub Desktop.

Select an option

Save Jesserc/24deb7573902fd589a659ec100d07f1d to your computer and use it in GitHub Desktop.
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