This template synergizes Foundry and Hardhat to offer a powerful, integrated environment for Ethereum smart contract development, testing, and deployment.
- Foundry: modern framework to write unit, fuzz, fork or invariant tests in solidity.
- Hardhat: generate artifacts, run scripts and test smart contracts in typescript.
- Viem: modern Ethereum library for blockchain interaction.
- Solhint: linter for Solidity code
- Prettier: code formatter for non-Solidity files
By integrating Foundry and Hardhat, developers can harness the strengths of both platforms. Foundry's exceptional testing capabilities ensure your contracts are robust and secure, while Hardhat's deployment, scripting, and artifact generation features streamline the development and integration of smart contracts with frontend applications.
Foundry is a cutting-edge Ethereum development toolkit renowned for its speed and efficiency, especially when it comes to testing smart contracts. It shines in several key areas:
- Invariant Testing: Validates contract integrity under varied conditions.
- Fuzz Testing: Exposes vulnerabilities by testing contracts with millions of random inputs.
- Fork Tests: Assesses contract performance in real-world blockchain conditions.
While Foundry excels in testing, Hardhat complements it by offering a rich environment for smart contract deployment, scripting, and interaction, especially useful for frontend development:
- Scripting and Deployment: Simplifies complex deployments and interactions.
- Quick Mocking and Calls: Facilitates frontend development by enabling easy simulation of contract interactions.
- Artifact Generation: Streamlines web integration with automatic generation of essential artifacts, either using viem or typechain.
Click the Use this template button at the top of the
page to create a new repository with this repo as the initial state.
This is a list of the most frequently needed commands.
Build the contracts:
$ bun run compileOr compile using hardhat only:
$ bun run compile:hhOr compile using forge:
$ bun run compile:forgeDelete all the build artifacts and cache directories:
$ bun run cleanGet a test coverage report using foundry:
$ bun run coverageFoundry typically uses git submodules to manage dependencies, but this template uses Node.js packages because submodules don't scale.
This is how to install dependencies:
- Install the dependency using your preferred package manager, e.g.
bun install dependency-name- Use this syntax to install from GitHub:
bun install github:username/repo-name
- Use this syntax to install from GitHub:
- Add a remapping for the dependency in remappings.txt, e.g.
dependency-name=node_modules/dependency-name
Note that OpenZeppelin Contracts is pre-installed, so you can follow that as an example.
Inspiration drawn from PaulRBerg's Foundry Template and Hardhat Template.
MIT License © 2024 @urataps. Explore the LICENSE for more information.