Implementing Payments in the Auction
Learn how to add payments support to the Auction smart contract.
We'll cover the following...
Now that we’ve learned how to use payments in Solidy, we'll add payment support in the Auction smart contract. After this lesson, users of our smart contract will be able to send bids to the auction and terminate the auction once it is over.
Adding new fields
To implement payment support in our smart contract, we first need to add a few additional fields and methods to keep track of the state of the bidding process.
The most important field here is the totalBids mapping that we'll use to keep track of the bid amounts for each user. All the users’ bids will be stored in the total Ether balance of the Auction smart contract, so we need this additional data structure to keep track of each user’s contribution amount. We'll also keep track of the account that made the largest bid in the highestBidder field and the total number of bids made during the auction in totalBidsNum.
We'll add two additional modifiers to enforce that some operations can be done only before the deadline, while others can only be executed after the deadline.
In both modifiers, we compare the current block’s timestamp with the auction deadline and ...