BlindAuction

Category: Auctions | Difficulty: Advanced | Chapters: Auctions | Concept: Sealed-bid auction with encrypted bids and public reveal

Sealed-bid auction using encrypted bids and confidential payments.

Why this example

This example focuses on Sealed-bid auction with encrypted bids and public reveal. It is designed to be self-contained and easy to run locally.

Quick start

npm install
npm run test:mocked -- test/auctions/BlindAuction.test.ts

Dependencies

Deployment plan

Step
Contract
Args
Saves As

1

PrizeItem

-

prizeItem

2

AuctionPaymentToken

$deployer, "Auction USD", "AUSD", ""

paymentToken

3

BlindAuction

@prizeItem, @paymentToken, 0, #Math.floor(Date.now()/1000), #Math.floor(Date.now()/1000)+3600

auction

Contract and test

Pitfalls to avoid

No pitfalls are highlighted in the tests for this example.

API Reference

Overview

Sealed-bid auction using encrypted bids and confidential payments.

Developer Notes

Example for fhEVM Examples - Auctions Category

beneficiary

The recipient of the highest bid once the auction ends

paymentToken

Confidential payment token

nftContract

Token for the auction prize

tokenId

Token ID of the prize NFT

prizeDeposited

Whether the prize NFT was deposited

auctionStartTime

Auction start time (unix timestamp)

auctionEndTime

Auction end time (unix timestamp)

winnerAddress

Winner address defined at the end of the auction

isNftClaimed

Indicate if the NFT of the auction has been claimed

TooEarlyError

Error thrown when a function is called too early

TooLateError

Error thrown when a function is called too late

InvalidAuctionTime

Thrown when the auction time range is invalid

WinnerNotYetRevealed

Thrown when attempting an action that requires the winner to be resolved

PrizeNotDeposited

Thrown when the prize was not deposited yet

OnlyBeneficiary

Thrown when a non-beneficiary calls a restricted action

PrizeAlreadyDeposited

Thrown when the prize is already deposited

OnlyWinner

Thrown when a non-winner attempts a winner-only action

NftAlreadyClaimed

Thrown when the NFT prize was already claimed

NoWinnerToReveal

Thrown when no valid winner exists to reveal

WinnerAlreadyRevealed

Thrown when the winning address has already been revealed

InvalidWinningHandle

Thrown when the decryption proof does not match the winning handle

Parameters

Name
Type
Description

expected

bytes32

The expected winning handle

provided

bytes32

The provided handle

onlyDuringAuction

onlyAfterEnd

onlyAfterWinnerRevealed

getEncryptedBid

Return the encrypted bid stored for a bidder.

Parameters

Name
Type
Description

account

address

Bidder address

Return Values

Name
Type
Description

[0]

euint64

The encrypted bid handle

getWinnerAddress

Return the decrypted winner address once revealed.

Return Values

Name
Type
Description

[0]

address

The winner address

constructor

Create the blind auction contract.

Parameters

Name
Type
Description

nftContractAddress

address

ERC721 prize contract

paymentTokenAddress

address

ERC7984 payment token

prizeTokenId

uint256

Token ID of the prize NFT

startTime

uint256

Auction start timestamp

endTime

uint256

Auction end timestamp

depositPrize

Deposit the NFT prize into the auction contract.

bid

Place an encrypted bid during the auction window.

Parameters

Name
Type
Description

encryptedAmount

externalEuint64

Encrypted bid amount handle

inputProof

bytes

Proof for the encrypted input

requestDecryptWinningAddress

Publish the encrypted winner address and bid for public decryption.

getWinningAddressHandle

Return the handle for the encrypted winning address.

Return Values

Name
Type
Description

[0]

bytes32

The encrypted winner address handle

getWinningBidHandle

Return the handle for the encrypted winning bid.

Return Values

Name
Type
Description

[0]

bytes32

The encrypted winning bid handle

winnerClaimPrize

Claim the NFT prize.

withdraw

Withdraw a bid from the auction (non-winners only).

Parameters

Name
Type
Description

bidder

address

Address of the bidder withdrawing

resolveAuction

Resolve the auction by verifying the decryption proof for the winner.

Parameters

Name
Type
Description

handlesList

bytes32[]

Handles signed by the gateway

cleartexts

bytes

Decrypted cleartexts

decryptionProof

bytes

Proof for the gateway signature

Last updated