Setting up a Hardhat Project
To setup a project that uses Hardhat for Ethereum contract development, do the following:
- Install a recent version of Node.js. We need the
npm
andnpx
commands for the rest of this chapter. - Create a new directory and enter it.
mkdir hello-world cd hello-world
- Initialize a new Node.js project.
The directory should contain a single file callednpm init -y
package.json
. - Install Hardhat by running the following command in the
hello-world
directory.
Thenpm install --save-dev hardhat
package.json
file will now have ahardhat
section underdevDependencies
. - Create a Hardhat project by running the following command. Choose the Create an empty hardhat.config.js option.
The directory will have a file callednpx hardhat
hardhat.config.js
with the following contents.
The number/** @type import('hardhat/config').HardhatUserConfig */ module.exports = { solidity: "0.8.17", };
0.8.17
specifies the version of the Solidity compiler.