Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.24;
- contract Auction {
- address public owner;
- address public highestBidder; // The highest bidder's address
- uint public highestBid; // The amount of the highest bid
- mapping(address => uint) public userBalances; // mapping for the amount to return
- constructor() public
- {
- // contractor
- // 1. Initialize highest bid and the bidder's address
- owner = msg.sender;
- highestBidder = 0;
- highestBid = 0;
- }
- function bid() payable public
- {
- // Funtion to process bid
- // 1. Check if the bid is greater than the current highest bid
- // 2. Update status variable and the amount to return
- if(highestBid < msg.value) {
- highestBidder = msg.sender;
- highestBid = msg.value;
- userBalances[msg.sender] = msg.value;
- }
- }
- function withdraw() public {
- // Function to withdraw the amount of bid to return
- // 1. Check if the amount to return is greater than zero
- // 2. Update status variablle and return bid
- if(userBalances[msg.sender] > 0) {
- msg.sender.transfer(userBalances[msg.sender]);
- userBalances[msg.sender] = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement