This project template integrates Hardhat for deployment and scripting with Foundry for fast, Solidity-based testing. Follow the instructions below to set up your environment, understand the project structure, and learn common commands.
Before you start, ensure you have the following installed:
-
Node.js v18
Install Node.js version 18 from nodejs.org. -
Yarn
Install Yarn from yarnpkg.com (or use npm if you prefer). -
Foundry (Forge) v1
Install Foundry by running:curl -L https://foundry.paradigm.xyz | bash foundryupVerify the installation with:
forge --version
The repository is organized as follows:
-
contracts/ Contains the Solidity source code for your contracts.
-
deploy/ Contains TypeScript deployment scripts. To enforce proper deployment order, name your files with numeric prefixes (e.g., 01_deploy_MyContract.ts, 02_deploy_OtherContract.ts).
-
deployment/ Stores deployment artifacts and information about deployed contracts (generated by hardhat-deploy).
-
lib/ Contains Foundry libraries (e.g., forge-std) used for testing and scripting.
-
scripts/ Contains scripts for interacting with contracts.
-
test/ Contains Solidity test files written in Foundry style (using ds-test). Within the test/ folder, there is an env/ subfolder that stores environment variable files (e.g., .env.localhost, .env.mainnet) for different networks during testing.
Below are some frequently used commands for compiling, testing, and deploying your contracts:
Compile Contracts & Generate TypeChain Files This command compiles your contracts and generates TypeScript types for interacting with them.
npm run typechainStart a Local Blockchain Node Launch a local blockchain using the configuration in hardhat.config.ts (by default, forked from Ethereum).
npx hardhat nodeList Accounts Display the available accounts.
npx hardhat accountsCheck the Current Block Number View the current block number.
npx hardhat blocknumberRun Foundry Tests via Hardhat This command runs tests written in Solidity (Foundry style) on a forked network.
npx hardhat forge-test --network localhost(You can specify filters, such as match-path or match-contract, via parameters in your custom task.)
Run Foundry Script via Hardhat This command runs tests written in Solidity (Foundry style).
npx hardhat forge-test --network localhostList Available Networks Show the networks defined in your Hardhat configuration.
npx hardhat networksDeploy Contracts Deploy your contracts using Hardhat Deploy.
npx hardhat deploy --network localhostRun a Specific Script Execute a specific Hardhat script (e.g., scripts/example.ts).
npx hardhat run scripts/example.ts --network localhost