Skip to main content
In this tutorial, you’ll learn how to deploy, mint, and burn ERC-721 tokens (NFTs) using Hardhat, Ethers, and OpenZeppelin contracts on the Hedera Testnet. We’ll cover setting up your project, writing and deploying an ERC-721 smart contract, minting an NFT to your account, and finally, burning an NFT. By the end, you’ll have hands-on experience with essential ERC-721 operations and interacting with smart contracts on Hedera.
You can take a look at the complete code in the Hedera-Code-Snippets repository.

Prerequisites


Table of Contents

  1. Project Setup
    1. Initialize Project
    2. Configure Hardhat
  2. Creating the ERC-721 Contract
  3. Deploy Your Smart Contract
  4. Minting an NFT
  5. Adding the Burn Functionality
  6. Burning an NFT
  7. Run tests

Video Tutorial

You can watch the video tutorial (which uses Hardhat version 2) or follow the step-by-step tutorial below (which uses Hardhat version 3).
Key differences in Hardhat 3:
  • compile → build
    npx hardhat compile is now npx hardhat build. This is the big one. The v3 migration guide explicitly shows using the build task.
  • project init switch
    v2 commonly used npx hardhat or npx hardhat init to bootstrap. In v3 it’s npx hardhat --init.
  • keystore helper commands are new
    v3’s recommended flow includes a keystore plugin with commands like npx hardhat keystore set HEDERA_RPC_URL and npx hardhat keystore set HEDERA_PRIVATE_KEY. These weren’t standard in v2.
  • Foundry-compatiable Solidity tests
    In addition to offering Javascript/Typescript integration tests, Hardhat v3 also integrates Foundry-compatible Solidity tests that allows developers to write unit tests directly in Solidity
  • Enhanced Network Management
    v3 allows tasks to create and manage multiple network connections simultaneously which is a significant improvement over the single, fixed connection available in version 2. This provides greater flexibility for scripts and tests that interact with multiple networks.
📚 Learn more from the official Hardhat documentation.

Step 1: Project Setup

Initialize Project

Set up your project by initializing the hardhat project:
Make sure to select “Hardhat 3 -> Typescript Hardhat Project using Mocha and Ethers.js” and accept the default values. Hardhat will configure your project correctly and install the required dependencies.

Install Dependencies

Next, install the required dependencies:
Before we make any changes to our Hardhat configuration file, let’s set some configuration variables we will be referring to within the file later.
For HEDERA_RPC_URL, we’ll have https://testnet.hashio.io/api
For HEDERA_PRIVATE_KEY, enter the HEX Encoded Private Key for your ECDSA account from the Hedera Portal.

Note

Hashio is intended for development and testing purposes only. For production use cases, it’s recommended to use commercial-grade JSON-RPC Relay or host your own instance of the Hiero JSON-RPC Relay.

Configure Hardhat

Update your hardhat.config.tsfile in the root directory of your project. This file contains the network settings so Hardhat knows how to interact with the Hedera Testnet.
hardhat.config.ts
You can verify the connection by running:
This command launches an interactive JavaScript console connected directly to the Hedera Testnet, providing access to the Ethers.js library for blockchain interactions. If you successfully enter this interactive environment, your Hardhat configuration is correct. To exit the interactive console, press ctrl + c twice. We won’t be using ignition and we will be removing the default contracts that comes with hardhat default project so we will remove all the unnecessary directories and files first:

Step 2: Creating the ERC-721 Contract

Create a new Solidity file (MyToken.sol) in our contracts directory:
contracts/MyToken.sol
This contract was created using the OpenZeppelin Contracts Wizard and OpenZeppelin’s ERC-721 standard implementation with an ownership model. The ERC-721 token’s name has been set to “MyToken.” The contract implements the safeMint function, which accepts the address of the owner of the new token and uses auto-increment IDs, starting from 0. Let’s compile this contract by running:
This command will generate the smart contract artifacts, including the ABI. We are now ready to deploy the smart contract.

Step 3: Deploy Your ERC-721 Smart Contract

Create a deployment script (deploy.ts) in scripts directory:
scripts/deploy.ts
In this script, we first retrieve your account (the deployer) using Ethers.js. This account will own the deployed smart contract. Next, we use this account to deploy the contract by calling MyToken.deploy(deployer.address). This passes your account address as the initial owner and signer of the deployment transaction. Deploy your contract by executing the script:
Copy the deployed address—you’ll need this in subsequent steps.
The output looks like this:

Step 4: Minting an NFT

Create a mint.ts script in your scripts directory to mint an NFT. Don’t forget to replace the <your-contract-address> with the address you’ve just copied.
scripts/mint.ts
The code mints a new NFT to your account ( deployer.address ). Then we verify the balance to see if we own an ERC-721 token of type MyToken. Mint an NFT:
Expected output:

Step 5: Adding the Burn Functionality

Update your contract to add NFT burning capability by importing the burnable extension and adding it to the interfaces list for your contract:
Redeploy:
Copy the new smart contract address and replace the address in the scripts/mint.ts script with your new address. Let’s mint a new NFT for the redeployed contract:

Step 6: Burning an NFT

Create a burn script (burn.ts ) in your scripts directory:
scripts/burn.ts
Again, ensure you update <your-contract-address> to interact with your correct contract. The script will burn the ERC-721 token with the ID set to 0, which is the ERC-721 token you’ve just minted. To be sure the token has been deleted, let’s print the balance for our account to the terminal. The balance should show a balance of 0. Burn the NFT:
Congratulations! 🎉 You have successfully learned how to deploy an ERC-721 smart contract using Hardhat, OpenZeppelin, and Ethers. Feel free to reach out in Discord!

Step 7: Run tests(Optional)

You can find both types of tests in the Hedera-Code-Snippets repository. You will find the following files:
  • contracts/MyToken.t.sol
  • test/MyToken.ts
Copy these files and then run the tests:
You can also run tests individually with either of these

Additional Resources

Writer: Michiel, DevRel Engineer

Editor: Editor: Luis, Sr Software Developer

Editor: Krystal, Senior DX Engineer

Editor: Kiran, Developer Advocate