Using Hardhat

Hardhat is a flexible and extensible Ethereum development environment used for compiling, testing, debugging, and deploying smart contracts.

This guide walks you through deploying an ERC-721 smart contract on Celeschain Testnet using Hardhatarrow-up-right.


Objectives

By the end of this guide, you will be able to:

  • Set up Hardhat for Celeschain Testnet

  • Create an ERC-721 NFT smart contract

  • Compile the smart contract

  • Deploy the smart contract to Celeschain Testnet

  • Interact with the deployed contract using Hardhat


Prerequisites

Node v18+

Ensure you have Node.js v18 or higher installed.

Wallet funds

Deploying to Celeschain requires gas. Fund your wallet with CLES (native token of Celeschain) from the testnet faucet.


Creating a Project

Start by setting up a new Node.js project:

Install Hardhat:

Create a Hardhat project:

Select:

  • Create a TypeScript project

  • Confirm project root

  • Choose yes for .gitignore

  • Choose yes to load the sample project


Configuring Hardhat for Celeschain

Add Celeschain Testnet to your Hardhat configuration.

Edit hardhat.config.ts:


Install Hardhat Toolbox

Load Environment Variables

Install dotenvarrow-up-right:

Create .env:

⚠️ Never commit your private key to a public repository!


Writing the NFT Smart Contract

Below is a simple ERC-721 contract that you will deploy:

contracts/NFT.sol:

Install OpenZeppelin:

Delete the default Lock.sol file.


Compiling the Smart Contract

Compile using:


Deploying the Smart Contract

Update scripts/deploy.ts:

Deploy to Celeschain Testnet:

After deployment, view your contract on:

Celeschain Testnet Explorer https://testnet-explorer.celeschain.xyzarrow-up-right

Last updated