Hardhat
Overview
Hardhat is an Ethereum development environment that helps developers manage and automate repetitive tasks for smart contract and DApp development, and can be used in the truffle project.
Prerequisites
This tutorial requires Node.js to be installed. You can download it through Node.js or run the following code to complete the installation. You can verify the correct installation by requesting the version of each installation package:
Create Hardhat project
Here we use the truffle project (please refer to the truffle document to create a project module using Truffle to complete the 1, 2, and 3 steps), then configure the package.json file, and add dependencies in devDependencies:
Need to reinstall dependencies
This will create a Hardhat config file (hardhat.config.js) in our project directory, and create a .secret in the project root directory to store the wallet address private key we need to use when operating the contract.
Create Hardhat script file
Create a script directory at the same level as contract to store Hardhat script files (example: deploy.ts), and then use ethers to write deployment scripts. First, create a local instance of the contract through the getContractFactory() method. Next, use the deploy() method included in the instance to initiate a smart contract. Finally, use deployed() to wait for the deployment to complete. After the contract is deployed, the contract address can be obtained in the MyContract instance. The script is a simplified version used in this tutorial.
Deploy contract
Use the run command to deploy the MyContract contract to Findora devnet
The contract can be deployed in a few seconds, and then you can see the contract address printed out on the terminal:
Interact with the contract
Create a local instance of the MyContract.sol contract, and then enter the address obtained when deploying the contract, connect this instance to an existing instance, and interact with it after connecting to the contract. When the console command is still running, call the method in the contract and pass in the correct parameters (If the method involves ERC20 type transfer, please authorize first).
Congratulations, you have completed the Hardhat basic operation guide!
Last updated