βοΈHardhat
What is 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.
Dependencies
Node.js v10+ LTS and npm (comes with Node)
Once we have those installed, you need to create an npm project by going to an empty folder, running npm init
, and following its instructions to install Hardhat. Once your project is ready, you should run:
To create your Hardhat project, run npx hardhat
in your project folder. Letβs create the sample project and go through these steps to try out a sample task and compile, test and deploy the sample contract.
The sample project used here comes from the Hardhat Quickstart guide, as well as its instructions.
Creating a project
To create a sample project, run npx hardhat
in your project folder. You should see the following prompt:
Choose the JavaScript project and go through these steps to compile, test and deploy the sample contract.
Checking the contractβ
The contracts
folder contains Lock.sol
, which is a sample contract which consistis of a simple digital lock, where users could only withdraw funds after a given period of time.
Setting up the contract
Go to
hardhat.config.js
Update the
hardhat-config
with matic-network-credentialsCreate
.env
file in the root to store your private key
NOTE
Note that the file above requires DOTENV, for managing environment variables and also ethers and etherscan. Make sure to install all those packages. Find more instructions on how to use DOTENV on this page.
Compiling the contract
To compile the contract, you first need to install Hardhat Toolbox:
Then, simply run to compile:
Testing the Contract
To run tests with Hardhat, you just need to type the following:
And this is an expected output:
Deploying on Gitshock Buitenzorg
Run this command in root of the project directory:
The contract will be deployed on Matic's Mumbai Testnet, and you can check the deployment status here: Gitshock Scan
Congratulations! You have successfully deployed Greeter Smart Contract. Now you can interact with the Smart Contract.
Last updated