Here’s how to install and set up Hardhat in your development environment:
1. Ensure Node.js and npm Are Installed
Hardhat requires Node.js and npm. Verify their installation with:
node -v
npm -v
If not installed, download and install the LTS version from the Node.js official website.
2. Create a Project Folder
Navigate to the desired location and create a new project folder:
mkdir my-hardhat-project
cd my-hardhat-project
3. Initialize an npm Project
Run the following command in your project directory to initialize a package.json
file:
npm init -y
4. Install Hardhat
Install Hardhat as a development dependency:
npm install --save-dev hardhat
5. Create a Hardhat Project
Once installed, set up your Hardhat project by running:
npx hardhat
You’ll see interactive options like:
- Create a basic sample project
- Create an advanced sample project
- Create an advanced sample project that uses TypeScript
- Create an empty hardhat.config.js
- Quit
Choose the option that best fits your needs. For example, select Create a basic sample project
and follow the instructions.
6. Install Recommended Dependencies
If you selected the basic sample project, it might recommend installing additional dependencies:
npm install --save-dev @nomicfoundation/hardhat-toolbox
7. Run the Default Task
Once the setup is complete, test your Hardhat installation by running the default sample task:
npx hardhat test
8. Start Developing
After setup, you’ll find a hardhat.config.js
file in the project root directory. Edit this file as needed to configure your development environment.
9. Install Additional Plugins (Optional)
Depending on your project requirements, you might need to install more plugins. For example:
To interact with Ethereum networks:
npm install --save-dev @nomiclabs/hardhat-ethers ethers
For deployment tools:
npm install --save-dev hardhat-deploy
With this, your Hardhat development environment is ready! If you have specific use cases, feel free to ask for further assistance.