hardhat

YU YU·2022년 2월 10일
0
post-custom-banner

1. What is hardhat?

1-1. Concept

Hardhat is method of development Dapp similar truffle
It is writing smart contract, and execute compile, test and deploy.
It use ethers.js instead of web3.js

1-2. Install

Truffle install global, but hardhat install and run for each individual project use npx

mkdir mydapp
yarn init -y
yarn add hardhat --dev
npx hardhat help



So Many packages are installed.

Select a basic sample project. if you want use typescript, you would select third.

just press enter

then, your structure of these folder is same like these.

1-3. structure

folder
- artifacts [result of compile]
- cache
- contracts [smart contract]
- scripts [Execution script of deploy etc]
- test [unit test]
- hardhat-config.js [environment of develop]

1-4. Plugin

hard-hat is based on plugin. so you should install some basic plugins.
Fist of all, let's install uint test plugin.

yarn add @nomiclabs/hardhat-waffle ethereum-waffle chai --dev

Install ethereum web library ethers.js

yarn add @nomiclabs/hardhat-ethers ethers --dev 

Then, install openzeppelin updagrade contract plugin

yarn add @openzeppelin/hardhat-upgrades ---dev

You can complete basic step to use hardhat typing the following.

1-5. hardhat task

npx hardhat compile
npx hardhat test --network rinkeby ./test/mytest.js
npx hardhat run --network rinkeby ./scripts/mydeploy.js
npx hardhat console --network rinkeby

So, let's typing these to know hardhat tasks.

npx hardhat help

2. how to writing contract?

2-1. Basic files.

Before writing contract, See basic files of the haradhat.

  • contract
  • scripts
  • test
  • hardhat-config.js

2-2. Writing contract

Create solidity file named SimpleStorageUpgrade in Contracts directory

profile
코딩 재밌어요!
post-custom-banner

0개의 댓글