Skip to main content

Using Hardhat

Hardhat is a development environment for Ethereum software. It consists of different components for editing, compiling, debugging and deploying your smart contracts and dApps, all of which work together to create a complete development environment. This Guide will walk you through the steps on how to deploy an ERC-20 token contract to the Fuse blockchain using Hardhat.

Prerequisites

  • Solidity programming knowledge
  • JavaScript knowledge
Open a new terminal and run these commands to create a new folder:
Inside the folder, initialize a project by running:
In the same directory where you installed Hardhat run:
Follow the prompts. A package.json file is added to the project dir, and we can then install Hardhat by running: Note: **Do you want to install this sample project’s dependencies with npm (hardhat @nomicfoundation/hardhat-toolbox)? (Y/n) › y **
Next install the Hardhat toolbox. The @nomicfoundation/hardhat-toolbox plugin bundles all the commonly used packages and Hardhat plugins to start developing with Hardhat.
If you are using VS Code Editor, you can add the folder and look at the contents. In this guide, we will focus on the hardhat.config.js file, Contracts and Scripts directories. Open the Contract folder, delete the default Lock.sol file and add a new file Token.sol. Update the contents of Token.sol with the following code:
To compile your contracts run:
It will return the response:
The compiled artifacts will be saved in the artifacts/ directory by default. If you need to customize the Solidity compiler options, then you can do so through the solidity field in your hardhat.config.js The next step is to deploy the contracts to the Fuse Blockchain. In Hardhat, deployments are defined through Ignition Modules. These modules are abstractions to describe a deployment; that is, JavaScript functions that specify what you want to deploy. Open ignition inside the project root’s directory, then, enter the directory named modules. Create a deploy.js and paste the following code:

Deploy Contract

Open the hardhat.config.js file and update the information on Fuse Network
Please note: The 0xPRIVATE_KEY is used to sign the Transaction from your EOA without the need to request permission. You must ensure the EOA that owns the Private Key is funded with some Fuse Tokens to pay for Gas when deploying the Smart Contract. Open a new terminal and deploy the smart contract to the Fuse network

How to verify contracts

To verify contracts with hardhat the hardhat-etherscan is used. This sounds counterintuitive and wrong, but the hardhat-etherscan plugin verifies contracts in the blockscout explorer. Add the following property to hardhat.config.js

Verify the contract on Fuse