This framework allows you to use the deploying toolset from the Hardhat library along with the testing suites from Foundry.
https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-foundry
Add Hardhat to your dev dependencies:
forge init
You will need to init a package.json:
yarn init -y
Then install hardhat:
yarn add -D hardhat
Once you've set up Hardhat, install the Hardhat-Foundry plugin:
yarn add --dev @nomicfoundation/hardhat-foundry
Then, add the following line to your hardhat.config.ts
file:
import "@nomicfoundation/hardhat-foundry";
Add Hardhat to your dev dependencies:
yarn add --dev hardhat
Once you've set up Hardhat, install the Hardhat-Foundry plugin:
yarn add --dev @nomicfoundation/hardhat-foundry
Then, add the following line to your hardhat.config.ts
file:
import "@nomicfoundation/hardhat-foundry";
With those requirements in place, initialize Foundry:
npx hardhat init-foundry
Now you can use both Hardhat and Foundry tools:
Task | Hardhat Command | Forge Command |
---|---|---|
Compile Contracts | npx hardhat compile |
Forge build |
Run Tests | npx hardhat test |
Forge test (-vv) options |
Add OpenZeppelin Contracts | yarn add @openzeppelin/contracts |
forge install OpenZeppelin/openzeppelin-contracts --no-commit |
Run Deployment Script | npx hardhat run scripts/deploy.ts |
see Forge Deploy Example |
Launch Node | npx hardhat node |
Anvil |
| | Deploy Contracts | Custom Hardhat script | See Forge Deploy Example Below|
forge create --rpc-url <your_rpc_url> \
--constructor-args <args> \
--private-key <your_private_key> \
--etherscan-api-key <your_etherscan_api_key> \
--verify \
src/ContractName.sol:NameOfContract
(Additional information or usage guide for Anvil can be added here)
Debugging:
If forge install doesn't pull all libraries from repo
manual install:
forge install foundry-rs/forge-std
forge install dapphub/ds-test