Recently, I have been revisiting Solidity, consolidating the finer details, and writing "WTF Solidity" tutorials for newbies.
Twitter: @0xAA_Science | @WTFAcademy_
Community: Discord|Wechat|Website wtf.academy
Codes and tutorials are open source on GitHub: github.com/AmazingAng/WTF-Solidity
In this lecture, I will introduce the Dutch Auction and explain how to issue an NFT
using the ERC721
standard through a simplified version of the Azuki
Dutch Auction code.
Dutch Auction
The Dutch Auction is a special type of auction. Also known as a "descending price auction," it refers to an auction where the bidding for the item being auctioned starts high and decreases sequentially until the first bidder bids (reaches or exceeds the bottom price) and it is sold.

In the cryptocurrency world, many NFTs are sold through Dutch auctions, including Azuki
and World of Women
, with Azuki
raising over 8000
ETH
through a Dutch auction.
The project team likes this type of auction for two main reasons:
-
The price of the Dutch auction slowly decreases from the highest price, allowing the project party to receive the maximum revenue.
-
The auction lasts a long time (usually more than 6 hours), which can avoid gas wars.
DutchAuction Contract
The code is simplified based on the code of Azuki
. The DutchAuction
contract inherits the ERC721
and Ownable
contracts previously introduced:
DutchAuction
State Variables
There are a total of 9
state variables in the contract, of which 6
are related to the auction. They are:
COLLECTION_SIZE
: Total number of NFTs.AUCTION_START_PRICE
: Starting price of the Dutch auction, is also the highest price.AUCTION_END_PRICE
: Ending price of the Dutch auction, also the lowest price/floor price.AUCTION_TIME
: Duration of the auction.AUCTION_DROP_INTERVAL
: Time interval when the price drops.auctionStartTime
: Starting time of the auction (blockchain timestamp,block.timestamp
).
DutchAuction
Function
There are a total of 9
functions in the Dutch auction contract. We will only introduce the functions related to the auction and not cover the functions related to ERC721
.
- Set auction start time: We declare the current block time as the start time in the constructor. The project owner can also adjust the start time through the
setAuctionStartTime()
function.
The constructor
function initializes a new ERC721
token with the name "WTF Dutch Auction" and the symbol "WTF Dutch Auction". It sets the auctionStartTime
to the current block timestamp.
The setAuctionStartTime
function is a setter function that updates the auctionStartTime
variable. It can only be called by the owner of the contract.
- Get the real-time auction price: The function
getAuctionPrice()
calculates the real-time auction price based on the current block time and relevant auction state variables.
If block.timestamp
is less than the start time, the price is the highest price AUCTION_START_PRICE
;
If block.timestamp
is greater than the end time, the price is the lowest price AUCTION_END_PRICE
;
If block.timestamp
is between the start and end times, the current decay price is calculated.
- User auctions and mints
NFT
: Users participate in a Dutch auction and mintNFT
by calling theauctionMint()
function to payETH
.
First, the function checks if the auction has started or if the number of NFTs
has exceeded the limit. Then, the contract calculates the auction cost based on the number of minted NFTs
and uses the getAuctionPrice()
function. It also checks if the user has enough ETH
to participate. If the user has enough ETH
, the contract mints NFTs
and refunds any excess ETH
. Otherwise, the transaction is reverted.
- Withdrawal of raised
ETH
by the project owner: The project owner can withdraw theETH
raised in the auction by using the functionwithdrawMoney()
.
Demo of Remix
-
Contract Deployment: First, deploy the
DutchAuction.sol
contract and set the auction start time through thesetAuctionStartTime()
function. In this example, the start time is March 19, 2023, 14:34 am, corresponding to UTC time 1679207640. You can search for the corresponding time on a tool website (such as here) during the experiment. -
Dutch Auction: Then, you can use the
getAuctionPrice()
function to get the current auction price. It can be observed that the price before the auction starts isstarting price AUCTION_START_PRICE
. As the auction proceeds, the auction price gradually decreases until it reaches thereserve price AUCTION_END_PRICE
, after which it no longer changes. -
Mint Operation: Complete mint through the
auctionMint()
function. In this example, because the time has exceeded the auction time, only thereserve price
was spent to complete the auction. -
Withdrawal of
ETH
: You can directly send the raisedETH
to the contract creator's address through thewithdrawMoney()
function.
Summary
In this lecture, we introduced the Dutch auction and explained how to issue ERC721
standard NFT
through Dutch auction
using a simplified version of the Azuki
Dutch auction code. The most expensive NFT
I auctioned was a piece of music NFT
by musician Jonathan Mann
. What about you?