0% found this document useful (0 votes)
13 views2 pages

Second Price Sealed Bid Auction Contract

The document outlines a Solidity smart contract for a second-price sealed bid auction. It allows participants to place sealed bids, reveal their bids, and concludes the auction by transferring the second-highest bid amount to the auction host. The contract includes mechanisms for bid placement, bid revealing, auction conclusion, and refunding excess deposits.

Uploaded by

markus00234
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Second Price Sealed Bid Auction Contract

The document outlines a Solidity smart contract for a second-price sealed bid auction. It allows participants to place sealed bids, reveal their bids, and concludes the auction by transferring the second-highest bid amount to the auction host. The contract includes mechanisms for bid placement, bid revealing, auction conclusion, and refunding excess deposits.

Uploaded by

markus00234
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract SecondPriceSealedBidAuction {
address payable public auctionHost;
uint public biddingDeadline;
uint public revealDeadline;
uint public minimalBid;
bool public auctionClosed;

struct Bid {
bytes32 concealedBid;
uint depositedAmount;
}

mapping(address => Bid) public bidRecords;


address public highestBidder;
uint public highestBid;
uint public secondHighestBid;

constructor(uint _biddingPeriod, uint _revealPeriod, uint _minimalBid) {


auctionHost = payable([Link]);
biddingDeadline = [Link] + _biddingPeriod;
revealDeadline = biddingDeadline + _revealPeriod;
minimalBid = _minimalBid;
}

function placeBid(bytes32 _sealedBid) external payable {


require([Link] < biddingDeadline, "Bidding phase over.");
require(bidRecords[[Link]].depositedAmount == 0, "Bid already
placed.");
bidRecords[[Link]] = Bid(_sealedBid, [Link]);
}

function revealBid(uint _actualBid, bytes32 _secret) external {


require([Link] >= biddingDeadline, "Bidding still active.");
require([Link] < revealDeadline, "Reveal phase ended.");

Bid storage storedBid = bidRecords[[Link]];


require([Link] > 0, "No bid found.");
require(keccak256([Link](_actualBid, _secret)) ==
[Link], "Incorrect bid details.");
require(_actualBid >= minimalBid, "Bid below minimum.");
require([Link] >= _actualBid, "Insufficient deposit.");

if (_actualBid > highestBid) {


secondHighestBid = highestBid;
highestBid = _actualBid;
highestBidder = [Link];
} else if (_actualBid > secondHighestBid) {
secondHighestBid = _actualBid;
}

[Link] = 0;
}

function concludeAuction() external {


require([Link] >= revealDeadline, "Reveal phase still active.");
require(!auctionClosed, "Auction already finalized.");
auctionClosed = true;

if (highestBidder != address(0)) {
uint finalPrice = secondHighestBid > 0 ? secondHighestBid : minimalBid;
[Link](finalPrice);
}
}

function withdrawExcess() external {


uint refund = bidRecords[[Link]].depositedAmount;
require(refund > 0, "No excess funds.");
bidRecords[[Link]].depositedAmount = 0;
payable([Link]).transfer(refund);
}
}

You might also like