Deploy a Dutch auction NFT contract on Cronos Mainnet using Hardhat where the price decreases over time until a buyer mints at an acceptable price.
TLDR:
This tutorial shows how to create and deploy a Dutch auction NFT contract on Cronos Mainnet using Hardhat.
The price starts high and lowers at fixed intervals; buyers can mint an NFT once the price is acceptable.
You’ll set up Hardhat, code and compile the contract, then verify and interact with it using the Cronos Explorer.
Because this deploys to Cronos Mainnet, deployment and minting spend real CRO — fund your wallet with a small amount to start.
Main article
A Dutch auction is a type of an auction in which the initial price of an NFT starts at its ceiling and lowers by a small amount at set intervals. Buyers make bids at reduced prices until the end of an auction. A Dutch auction continues until either all assets are sold out or the auction time ends.The objective of this tutorial is to familiarize you with the Cronos network, Hardhat, and Dutch auction smart contracts. In the end of the tutorial, you will be able to create a simple Dutch auction smart contract to help you sell your NFTs to the highest bidder.Specifically, in this tutorial, you will:
Create a Dutch auction smart contract.
Deploy and verify the contract on Cronos Mainnet through a node deployed with Chainstack.
This tutorial uses Hardhat 2. The hardhat package now installs Hardhat 3 by default, which uses a different project format, so install Hardhat 2 through its hh2 tag. In an empty project directory, run:
npm init -ynpm install --save-dev hardhat@hh2
Initialize a Hardhat project
In your project directory, run npx hardhat init. Select Create a JavaScript project and agree to install the sample project’s dependencies, which include @nomicfoundation/hardhat-toolbox with ethers v6. This creates a sample project with a smart contract draft.
Install additional dependencies
To complete the project, we need to install several additional dependencies.The OpenZeppelin Contract library allows you to inherit smart contracts. To install it, run:
npm i @openzeppelin/contracts
The dotenv library allows you to export and keep sensitive data securely. To install it, run:
npm i dotenv
Contract verification uses @nomicfoundation/hardhat-verify, which is already bundled in the @nomicfoundation/hardhat-toolbox the sample project installed — no separate verification plugin is needed. You point it at the Cronos Explorer in the Hardhat config below.You need to create an environment file to store your sensitive data with the project. To create it, in your project directory, run:
touch .env
Create and compile the contract
Navigate to your previously created project directory and go to the contracts directory. In the directory, create your Dutch auction smart contract: DutchAuction.sol.
// SPDX-License-Identifier: MITpragma solidity ^0.8.20;import "@openzeppelin/contracts/token/ERC721/ERC721.sol";import "@openzeppelin/contracts/access/Ownable.sol";contract MyToken is ERC721, Ownable { uint256 private _nextTokenId; uint256 public immutable startPrice = 10 ether; uint256 public immutable startAt; uint256 public immutable endsAt; uint256 public immutable endPrice = 5 ether; uint256 public immutable discountRate = 0.01 ether; uint256 public duration = 500 minutes; uint256 public immutable MAX_SUPPLY = 100; mapping (address => bool) public onlyOne; constructor() ERC721("CronosNFT", "CroNFT") Ownable(msg.sender) { startAt = block.timestamp; endsAt = block.timestamp + duration; } function price() public view returns (uint256) { if (block.timestamp > endsAt ) { return endPrice; } uint256 minutesElapsed = (block.timestamp - startAt) / 60; return startPrice - (minutesElapsed * discountRate); } function safeMint(address to) public payable { require(msg.value >= price(), "Not enough ether sent"); require(!onlyOne[msg.sender], "Sorry, Address already has 1 NFT!"); uint256 tokenId = _nextTokenId; require(tokenId < MAX_SUPPLY, "No more items left."); _nextTokenId++; onlyOne[msg.sender] = true; _safeMint(to, tokenId + 1); } function withdraw() public onlyOwner { payable(owner()).transfer(address(this).balance); }}
The contract implementation is the following:
The price of an NFT starts at 10 ether and decreases to 5 ether over 500 minutes. A maximum of 100 NFTs can be minted.
The contract uses the onlyOne mapping to ensure that each address can only own one NFT from your collection.
The contract sets the values of the start and end price, which cannot be changed later on.
The function price() uses block.timestamp to calculate the price of an NFT each time the safeMint function is called.
If all the required conditions are satisfied, the wallet address gets an NFT minted. The contract records the mint before calling _safeMint, so a receiving contract can’t mint a second NFT by calling back into safeMint.
To compile the contract, in your project directory, run:
npx hardhat compile
Fund your account
To deploy your smart contract on Cronos Mainnet, the deploying wallet needs CRO to cover gas. Fund it with a small amount of CRO from an exchange or an existing wallet.
Set up the environment and configuration files
In your project directory, navigate to a previously created environment file and edit it to add the following data:
dotenv — library to import your sensitive data from the environment file securely
solidity — the compiler version and EVM target. OpenZeppelin Contracts 5 uses the Cancun mcopy instruction, and Hardhat 2 compiles for an older EVM by default, so set evmVersion to cancun, which Cronos supports
cronos — the Cronos Mainnet network to deploy the contract to
url — your Cronos node HTTPS endpoint imported from the environment file
accounts — your MetaMask wallet private key imported from the environment file
etherscan — Cronos Explorer verification settings: your API key plus the customChains entry that points hardhat-verify at the Cronos Explorer
Deploy the Dutch auction contract
In your project directory, navigate to the scripts directory and create the DeployDutch.js file.
Edit the DeployDutch.js file to add the basic deployment script of Hardhat:
where CONTRACT_ADDRESS your contract address returned at the previous step
Interact with the contract
Now that your contract is verified, the Cronos Explorer is effectively a front-end instance for your contract.
Conclusion
This tutorial guided you through the basics of using Hardhat to deploy a Dutch auction smart contract to Cronos Mainnet, and verify it against the Cronos Explorer with hardhat-verify.Because this deploys to Cronos Mainnet, every deployment and mint spends real CRO — keep amounts small while you experiment.
About the author
Priyank Gupta
Developer Advocate @ Chainstack
BUIDLs on Ethereum, zkEVMs, and The Graph protocol
Part-time Rust aficionado