Skip to content

Hardhat 3 Setup

Hardhat 3 setup with node:test runner explorer in VSCode

Terminal window
# add hardhat alias as hh to .zshrc
alias hh="npx hardhat"
Terminal window
mkdir hardhat-example
cd hardhat-example
pnpm dlx hardhat --init
Hardhat options while initialization
Terminal window
👷 Welcome to Hardhat v3.0.9 👷
Which version of Hardhat would you like to use? · hardhat-3
Where would you like to initialize the project?
Please provide either a relative or an absolute path: · .
What type of project would you like to initialize? · node-test-runner-viem
Template files copied
You need to install the necessary dependencies using the following command:
pnpm add --save-dev "hardhat@^3.0.9" "@nomicfoundation/hardhat-toolbox-viem@^5.0.0" "@nomicfoundation/hardhat-ignition@^3.0.0" "@types/node@^22.8.5" "forge-std@foundry-rs/forge-std#v1.9.4" "typescript@~5.8.0" "viem@^2.30.0"
Do you want to run it now? (Y/n) · true
pnpm add --save-dev "hardhat@^3.0.9" "@nomicfoundation/hardhat-toolbox-viem@^5.0.0" "@nomicfoundation/hardhat-ignition@^3.0.0" "@types/node@^22.8.5" "forge-std@foundry-rs/forge-std#v1.9.4" "typescript@~5.8.0" "viem@^2.30.0"



Add required VSCode extension for test explorer

Section titled “Add required VSCode extension for test explorer”

Add required settings in settings.json of VSCode

Section titled “Add required settings in settings.json of VSCode”
{
"nodejs-testing.extensions": [
{
"extensions": ["mjs", "cjs", "js"],
"parameters": []
},
{
"extensions": ["mts", "cts", "ts"],
"parameters": ["--import", "tsx"]
}
]
}

Terminal window
pnpm add -D tsx
# Don't forget to build before running tests using the explorer
hh build
#Run tests from command line
hh test