Skip to content

RodgersChayuga/the-auction-smart-contract

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

THE AUCTION SMART CONTRACT

This code defines a smart contract for an auction with features for placing bids, canceling, and finalizing the auction.

Here's a breakdown of the functionalities:

1. Auction Setup:

Tracks the owner's address (owner).
Defines the starting and ending block numbers (startBlock and endBlock) for the auction duration.
Stores a reference hash (ipfsHash) to the auction details likely stored on IPFS (a decentralized storage network).
Sets the initial auction state (auctionState) to "Running".
Initializes variables for highest binding bid (highestBindingBid), highest bidder (highestBidder), and bid increment (bidIncrement).
A boolean ownerFinalized tracks if the owner has claimed the funds.

2. State Management:

Defines an enum called State with possible values: "Started", "Running", "Ended", and "Canceled".
Ensures actions are performed only in the appropriate state using modifiers.

3. Placing Bids:

The placeBid function allows users to submit bids.
Requires the auction to be running (afterStart and beforeEnd modifiers).
Enforces a minimum bid amount (commented out in this example).
Calculates the current bid for the user (including the sent amount).
Updates the highest binding bid considering the current bid and existing bids.
Tracks the highest bidder and their bid amount.
Returns a boolean indicating a successful bid placement.

4. Canceling Auction:

The cancelAuction function allows the owner to cancel the auction before it ends (onlyOwner and beforeEnd modifiers).
Changes the auction state to "Canceled".

5. Finalizing Auction:

The finalizeAuction function handles finalizing the auction and distributing funds.
Requires the auction to be either canceled or ended (require statement).
Allows the owner or any bidder with a bid to call this function.
Determines the recipient and value based on the auction state and caller:
Canceled auction: Refunds the sender's bid.

Ended auction (not canceled):
If the owner finalizes for the first time (ownerFinalized check), they receive the highest binding bid.
Otherwise, the highest bidder receives their bid minus the highest binding bid, or a bidder receives their full bid back if they are not the highest bidder.
Resets the recipient's bid amount to avoid multiple payouts.
Transfers the funds to the recipient.

Overall, this smart contract provides a secure and automated way to conduct auctions on the blockchain. It ensures transparency in bidding and fair distribution of funds after the auction concludes.


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published