>
>
Complete the 2023 Solidity Survey here
>
>

#Integrating with Foundry

This guide explains how to combine Hardhat and Foundry in the same project using our @nomicfoundation/hardhat-foundry plugin.

# Setting up a hybrid project

How to set up a project that combines Hardhat and Foundry depends on whether you have an existing Hardhat project or an existing Foundry project.

#Adding Foundry to a Hardhat project

TIP

Foundry relies on Git to work properly. Make sure your project is already a Git repository, or type git init to initialize one.

If you have an existing Hardhat project and you want to use Foundry in it, you should follow these steps.

First, run forge --version to make sure that you have Foundry installed. If you don't, go here to get it.

After that, install the @nomicfoundation/hardhat-foundry plugin:

npm 7+
npm 6
yarn
npm install --save-dev @nomicfoundation/hardhat-foundry
npm install --save-dev @nomicfoundation/hardhat-foundry
yarn add --dev @nomicfoundation/hardhat-foundry

and import it in your Hardhat config:

TypeScript
JavaScript
import "@nomicfoundation/hardhat-foundry";
require("@nomicfoundation/hardhat-foundry");

To complete the setup, run npx hardhat init-foundry. This task will create a foundry.toml file with the right configuration and install forge-std.

#Adding Hardhat to a Foundry project

If you have an existing Foundry project and you want to use Hardhat in it, follow these steps.

First, if you don't have a package.json already in your project, create one with npm init.

Then install Hardhat, the Hardhat Toolbox, and the @nomicfoundation/hardhat-foundry plugin:

npm 7+
npm 6
yarn
npm install --save-dev @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-foundry
npm install --save-dev @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-foundry
yarn add --dev hardhat @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-foundry

After that, initialize a Hardhat project with npx hardhat init. Choose the "Create an empty hardhat.config.js" option, and then import the plugin in hardhat.config.js:

require("@nomicfoundation/hardhat-toolbox");
require("@nomicfoundation/hardhat-foundry");

You should now be able to compile your project with Hardhat and to add Hardhat scripts and tests.

# Working with a combined setup

Once you've set up a project as explained in the previous section, you'll be able to use both Hardhat and Foundry in it. These are some of the things you can do:

Check our docs and Foundry docs to learn more.