Discover how you can build your own NFT auction where the highest bid gets an NFT
packages/hardhat/contracts
folder and check out what contracts we have there.Auction.sol
smart contract which contains all the logic for NFT auction.onERC721Received
which you can find at the bottom of the contract.createTokenAuction
function. It takes an address of NFT contract which in our case is an address of YourCollectible.sol
deployed to our local chain, unique token ID which is going to be sold, minimum bid and duration in seconds.bid
function 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.executeSale
is 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.cancelAuction
allows to prematurely cancel the auction and lets the initial owner to get back his NFT.