Decentralized eBay Smart Contract Description: This Solidity smart contract is a basic implementation of a decentralized auction platform similar to eBay. It allows users to list items for auction, place bids on listed items, and handle the transfer of funds when an auction ends. By leveraging blockchain technology, the contract ensures transparency, immutability, and trustless transactions between users.
How It Works:
Item Listing:
Function: listItem(string _name, string _description, uint _minPrice) Role: Sellers can list items by providing a name, description, and minimum price. Process: The function increments the item count and creates a new Item struct, storing it in the items mapping. Placing Bids:
Function: placeBid(uint _itemId) Role: Buyers can place bids on listed items. Process: The function checks if the auction is open and if the bid is higher than the minimum price and current highest bid. If these conditions are met, the bid is accepted, and previous highest bids are stored in pendingReturns for later withdrawal. Withdrawing Bids:
Function: withdraw() Role: Users can withdraw their bids if they are outbid. Process: The function allows users to retrieve their funds from the pendingReturns mapping. Ending Auctions:
Function: endAuction(uint _itemId) Role: Sellers can end the auction for their item. Process: The function transfers the highest bid amount to the seller and marks the auction as closed. The highest bidder becomes the winner of the auction. Key Features:
Transparency: All transactions and bids are recorded on the blockchain. Security: Funds are handled by the contract, reducing the risk of fraud. Trustlessness: Users interact directly with the smart contract, eliminating the need for intermediaries. This smart contract provides a foundational framework for a decentralized auction system, promoting fair and secure transactions on the Ethereum blockchain.
Structs and Enums:
Item: Represents an item up for auction with details like id, seller, name, description, minPrice, highestBid, highestBidder, and state. AuctionState: Enum representing whether the auction is Open or Closed. Mappings:
items: Maps item IDs to Item structs. pendingReturns: Keeps track of bids that need to be returned to users when they are outbid. Events:
ItemListed: Emitted when a new item is listed. BidPlaced: Emitted when a new bid is placed. AuctionEnded: Emitted when an auction is ended. Functions:
listItem: Allows a user to list a new item for auction. placeBid: Allows a user to place a bid on an item. withdraw: Allows users to withdraw their bids if they are outbid. endAuction: Allows the seller to end the auction and transfer the highest bid to the seller.