- 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.
- Interact with the deployed contract.
Prerequisites
- Chainstack account to deploy a reliable Cronos RPC endpoint.
- Hardhat to compile and deploy the contract.
- MetaMask to interact with the contract through your Chainstack node.
Overview
To get from zero to deploying your own Dutch auction smart contract on Cronos Mainnet, do the following:- With Chainstack, create a .
- With Chainstack, join Cronos Mainnet.
- With Chainstack, access your Cronos node endpoint.
- With Hardhat, set up your development environment.
- With Hardhat, create and compile your Dutch auction contract.
- With MetaMask, fund your wallet with CRO to cover deployment and minting gas.
- With Hardhat, deploy your Dutch auction contract.
- With the Cronos Explorer, interact with your Dutch auction contract.
Step-by-step
Create a public chain project
See Create a project.Join Cronos Mainnet
See Join a public network.Get your Cronos node endpoint
See View node access and credentials.Install Hardhat
See Hardhat documentation.Initialize a Hardhat project
In your project directory, runnpx hardhat. Select Create a JavaScript project and agree to install the sample project’s dependencies. This will create a sample project directory 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:@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:
Create and compile the contract
-
Navigate to your previously created project directory and go to the
contractsdirectory. In the directory, create your Dutch auction smart contract:DutchAuction.sol.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
onlyOnemapping 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()usesblock.timestampto calculate the price of an NFT each time thesafeMintfunction is called. - If all the required conditions are satisfied, the wallet address gets an NFT minted.
-
To compile the contract, in your project directory, run:
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:
RPC_URL— your Cronos node HTTPS endpoint deployed with Chainstack. See also View node access and credentials.PRIVATE_KEY— the private key of your MetaMask wallet, funded with enough CRO to cover deployment gas.API_KEY— a Cronos Explorer API key used to verify the deployed contract. Create one in the Cronos Explorer (see Block explorer and API keys).
-
In your project directory, navigate to the Hardhat configuration file and replace the current data with the following data:
where
dotenv— library to import your sensitive data from the environment file securelycronos— the Cronos Mainnet network to deploy the contract tourl— your Cronos node HTTPS endpoint imported from the environment fileaccounts— your MetaMask wallet private key imported from the environment fileetherscan— Cronos Explorer verification settings: your API key plus thecustomChainsentry that pointshardhat-verifyat the Cronos Explorer
Deploy the Dutch auction contract
-
In your project directory, navigate to the scripts directory and create the
DeployDutch.jsfile. -
Edit the
DeployDutch.jsfile to add the basic deployment script of Hardhat: -
In your project directory, run the following script:
The contract will deploy and the terminal will return the contract address. Use this address to verify and interact with your contract.
Verify your contract on Cronos Mainnet
Once your contract is deployed, verify it on Cronos Mainnet. In your terminal, run: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 withhardhat-verify.
Because this deploys to Cronos Mainnet, every deployment and mint spends real CRO — keep amounts small while you experiment.
