Hardhat
What is Hardhat
Hardhat is a development environment to compile, deploy, test, and debug your smart contract.
Installation
Hardhat is used through a local installation in your project.
To install it, you need to create an npm project by going to an empty folder, running npm init
, and following its instructions. Once your project is ready, you should run
To use your local installation of Hardhat, you need to use npx
to run it (i.e. npx hardhat
).
Hardhat will let you know how, but, in case you missed it, you can install them with npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers
Quick Start
To create your Hardhat project run npx hardhat
in your project folder:
If you select Create a sample project a simple project creation wizard will ask you some questions and create a project with the following structure:
contracts/
is where the source files for your contracts should be.test/
is where your tests should go.scripts/
is where simple automation scripts go
Create Contract
You can write your own smart contract or download any contract written by Solidity.
Config Hardhat for Mainnet
Go to hardhat.config.js
Update the config with crendentials.
Compile
To compile your contracts in your Hardhat project, use the built-in compile
task:
Deploying your contract
You can deploy the Greeter
contract from the sample project with a deploy script scripts/deploy.js
like this:
As general rule, you can target any network configured in the hardhat.config.js
Reference
Last updated