Discover how you can build your own NFT auction where the highest bid gets an NFT
packages/hardhat/contractsfolder and check out what contracts we have there.
Auction.solsmart contract which contains all the logic for NFT auction.
onERC721Receivedwhich you can find at the bottom of the contract.
createTokenAuctionfunction. It takes an address of NFT contract which in our case is an address of
YourCollectible.soldeployed to our local chain, unique token ID which is going to be sold, minimum bid and duration in seconds.
bidfunction which basically checks that the bid which is going to be made is currently the highest one. Note that we store the entire history of all bids made to allow us to return funds back to users who did not win an auction.
executeSaleis a function used to complete the auction and identify the winner. It simply checks the last element of all bids placed and transfers NFT to the winner. If no bids were made, NFT is returned back to the initial owner.
cancelAuctionallows to prematurely cancel the auction and lets the initial owner to get back his NFT.