- Reference repository
- NPM and Yarn
- VS Code
- VS Code plugins
- source control
- unit tests
- scripts
- Testing passing
- Breaking tests
https://github.com/OpenZeppelin/openzeppelin-contracts
https://git-scm.com/book/en/v2/Getting-Started-The-Command-Line
https://yarnpkg.com/getting-started
https://yarnpkg.com/getting-started/usage
https://code.visualstudio.com/docs
git clone https://github.com/OpenZeppelin/openzeppelin-contracts.git
cd openzeppelin-contracts
yarn install
yarn compile
...
$ hardhat compile
...
Compiled 267 Solidity files successfully
Done in 18.79s.
"scripts": {
"compile": "hardhat compile",
"coverage": "env COVERAGE=true hardhat coverage",
"docs": "oz-docs",
"docs:watch": "npm run docs watch contracts 'docs/*.hbs' docs/helpers.js",
"prepare-docs": "scripts/prepare-docs.sh",
"lint": "npm run lint:js && npm run lint:sol",
"lint:fix": "npm run lint:js:fix && npm run lint:sol:fix",
"lint:js": "eslint --ignore-path .gitignore .",
"lint:js:fix": "eslint --ignore-path .gitignore . --fix",
"lint:sol": "solhint 'contracts/**/*.sol' && prettier -c 'contracts/**/*.sol'",
"lint:sol:fix": "prettier --write \"contracts/**/*.sol\"",
"clean": "hardhat clean && rimraf build contracts/build",
"prepare": "npm run clean && env COMPILE_MODE=production npm run compile",
"prepack": "scripts/prepack.sh",
"release": "scripts/release/release.sh",
"version": "scripts/release/version.sh",
"test": "hardhat test",
"test:inheritance": "node scripts/inheritanceOrdering artifacts/build-info/*",
"gas-report": "env ENABLE_GAS_REPORT=true npm run test"
},
yarn test test/token/ERC20/ERC20.test.js
Output
$ hardhat test test/token/ERC20/ERC20.test.js
...
76 passing (5s)
Done in 8.39s.
code contracts/token/ERC20/ERC20.sol
function decimals() public view virtual override returns (uint8) {
return 42;
}
yarn test test/token/ERC20/ERC20.test.js
Output
$ hardhat test test/token/ERC20/ERC20.test.js
...
Compiled 28 Solidity files successfully
...
75 passing (7s)
1 failing
1) Contract: ERC20
has 18 decimals:
AssertionError: expected '42' to equal '18'
+ expected - actual
-42
+18
- Composability
- Upgradeability
- Maintainability and readability
- Managing work flow and progress
- Reaching peace of mind
- Creating a base repository
- Setup hardhat with typescript
- Configure VS Code
- Hardhat scripts and tasks
- VS Code extensions recommended
https://hardhat.org/getting-started/
https://hardhat.org/guides/typescript.html
https://hardhat.org/guides/vscode-tests.html
Using Yarn Berry:
yarn init -2
...
yarn config set nodeLinker node-modules
yarn add hardhat --dev
yarn hardhat init
"Create a TypeScript project"
...
.gitignore? Y
yarn add --dev [list of suggested dev dependencies above]
yarn add mocha --dev
code .
.mocharc.json file:
{
"require": "hardhat/register",
"timeout": 40000,
"_": ["tests/**/*.ts"]
}
Suggested renaming:
// Renaming "test" folder
mv test tests
If using Yarn Berry with PnP:
// Setting up yarn sdk for vscode
yarn dlx @yarnpkg/sdks vscode
// Press ctrl+shift+p in a TypeScript file
// Choose "Select TypeScript Version"
// Pick "Use Workspace Version"
hardhat.config.ts file:
{
const config: HardhatUserConfig = {
...
paths: { tests: "tests" },
...
}
}
tsconfig.json file:
...
"include": ["./scripts", "./tests", "./typechain"],
"files": ["./hardhat.config.ts"],
...
Create env file in root project folder
.env file:
MNEMONIC="here is where your twelve words mnemonic should be put my friend"
PRIVATE_KEY="<your private key here if you don't have a mnemonic seed>"
INFURA_API_KEY="********************************"
INFURA_API_SECRET="********************************"
ALCHEMY_API_KEY="********************************"
ETHERSCAN_API_KEY="********************************"
Edit the environment with your keys:
code .env
Test it out:
yarn hardhat compile
yarn hardhat test
Accounts task:
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();
for (const account of accounts) {
console.log(account.address);
}
});
Test it out:
yarn hardhat accounts
- Syntax for typescript scripts
- How the project operates
- Writing a test file
- Using Ethers.js library
- Using Hardhat toolbox
- Using Typechain library
- Testing syntax
- Running a test file
https://hardhat.org/hardhat-chai-matchers/docs/overview
https://github.com/dethcrypto/TypeChain
rm contracts/*
rm scripts/*
rm tests*
yarn hardhat clean
- Create Github Issues with your questions about this lesson
- Read the references
- Get to know Hardhat and Ethers.js documentation