The Complete Hands-On Hardhat Tutorial | by Rodrigo Herrera I. | Feb, 2022

3 practical projects to help you get started

Rodrigo Herrera I.

Hardhat Network

simple-smart-contracts-project-structure

Installation and Environment Setup

node -v
mkdir hardhat-tutorial
cd hardhat-tutorial
mkdir project1
cd project1
npm init -y
npm install --save-dev hardhat
npx hardhat
npm install --save-dev @nomiclabs/hardhat-ethers ethers @nomiclabs/hardhat-waffle ethereum-waffle chai
hardhat.config.js

Creating the contract

mkdir contracts
touch contracts/Token.sol
Token.sol

Testing the contract

mkdir test
touch test/token.js
token.js
npx hardhat test
npx hardhat test test/token.js

Deploying the contract

npm install dotenv
touch .env
hardhat.config.js
mkdir deployments
touch deployments/deployToken.js
deployToken.js
npx hardhat compile
npx hardhat run deployments/deployToken.js --network rinkeby

Verifying the contract

npm install --save-dev @nomiclabs/hardhat-etherscan
hardhat.config.js
npx hardhat verify --network rinkeby CONTRACT_ADDRESS "100000000000000000000000"

Ok, so what went wrong?

mkdir project2
cd project2
npm init -y
npm install --save-dev hardhat
npx hardhat
npm install --save-dev @nomiclabs/hardhat-ethers ethers @nomiclabs/hardhat-waffle ethereum-waffle chai
npm install dotenv
touch .env
hardhat.config.js
mkdir test
touch test/parityHack.js
parityHack.js
npx hardhat test 
mkdir project3
cd project3
npm init -y
npm install --save-dev hardhat
npm install --save-dev @nomiclabs/hardhat-ethers
npx hardhat
mkdir contracts
touch contracts/Hello.sol
Hello.sol
npx hardhat compile
mkdir deployments
touch deployments/deployHello.js
deployHello.js
npx hardhat node
npx hardhat node
npx hardhat run --network localhost deployments/deployHello.js
touch main.js
node main.js

Additional plugins and tasks

Leave a Comment