Hardhat 3 projects
A Hardhat Project is an npm package that uses Hardhat. In other words, it’s a directory with a package.json file, and a Hardhat config file either in the same directory or one of its subdirectories.
Hardhat project root
Section titled “Hardhat project root”The Hardhat project root directory is the directory containing the package.json file, matching the behavior of npm.
For example, in this case:
Directorydirectory
- package.json
Directoryconfig/
- hardhat.config.ts
directory is the project root, not config.
Recommended structure
Section titled “Recommended structure”We recommend keeping both the package.json and the hardhat.config.ts in the root of the project, and installing hardhat there.
Directoryroot
- package.json Has
hardhatinstalled - hardhat.config.ts
- package.json Has
Nested projects and Hardhat installation
Section titled “Nested projects and Hardhat installation”The package.json of the Hardhat project doesn’t need to install Hardhat directly. The only requirement is that your config needs to be able to import it. This can be helpful for integration tests of plugins and custom setups.
For example, in this case:
Directorydirectory
- package.json Has
hardhatinstalled - hardhat.config.ts
Directorytests
Directoryexample-project
- package.json Doesn’t have
hardhatinstalled - hardhat.config.ts
- package.json Doesn’t have
- package.json Has
Both directory and example-project will be Hardhat projects, despite hardhat only being installed in directory.
Usage with monorepos
Section titled “Usage with monorepos”If you’re using a monorepo, each package can have multiple projects, as explained above. However, we recommend using the Recommended structure in each of your packages.