This project showcases a Hardhat 3 Beta project using the native Node.js test runner (node:test) and the viem library for Ethereum interactions.
To learn more about the Hardhat 3 Beta, please visit the Getting Started guide. To share your feedback, join the Hardhat 3 Beta Telegram group or open an issue.
This example project includes:
- A simple Hardhat configuration file.
- Foundry-compatible Solidity unit tests in
contracts/tests/. - TypeScript integration tests using
node:testand viem. - Examples demonstrating how to connect to different types of networks, including locally simulating OP mainnet.
- CI workflows: lint, test, coverage, and Slither static analysis.
- Node.js 24+
- pnpm 9+
pnpm installpnpm lintRun all tests (Solidity and Node.js):
pnpm testRun only Solidity tests:
pnpm exec hardhat test solidityRun only Node.js tests:
pnpm exec hardhat test nodejsRun tests matching a pattern:
pnpm exec hardhat test solidity --grep "Token20"
pnpm exec hardhat test nodejs --test-name-pattern "Token20"pnpm coverageRuns the full test suite. For detailed Solidity coverage reports you can add a coverage plugin (e.g. solidity-coverage).
For deployment and scripts that need private keys or RPC URLs, use Hardhat Configuration Variables or environment variables.
Using Hardhat Keystore (recommended for local dev):
pnpm exec hardhat keystore set SEPOLIA_PRIVATE_KEY
pnpm exec hardhat keystore set SEPOLIA_RPC_URLUsing environment variables:
Export before running commands, or use a .env file (do not commit secrets):
export SEPOLIA_PRIVATE_KEY=0x...
export SEPOLIA_RPC_URL=https://...The config expects:
SEPOLIA_PRIVATE_KEY– account used for deployment/transactions on Sepolia.SEPOLIA_RPC_URL– Sepolia RPC endpoint (optional if using a default).
pnpm exec hardhat compileDeploy to a local simulated chain:
pnpm exec hardhat ignition deploy ignition/modules/Counter.ts
pnpm exec hardhat ignition deploy ignition/modules/Token20.ts
pnpm exec hardhat ignition deploy ignition/modules/Token721.ts
pnpm exec hardhat ignition deploy ignition/modules/Token1155.tsDeploy to Sepolia (account must have funds and config/keystore set):
pnpm exec hardhat ignition deploy --network sepolia ignition/modules/Counter.ts
pnpm exec hardhat ignition deploy --network sepolia ignition/modules/Token20.ts
# ... same for Token721, Token1155Set the deployer key via keystore or env (see Environment and Secrets) before running.
- Lint:
pnpm lint - Test:
pnpm test - Coverage:
pnpm coverage - Slither: see .github/workflows/slither.yaml – runs on push/PR, compiles with
hardhat-ci.config.ts, uploads SARIF.
- Contracts:
contracts/(e.g.Counter.sol,Token20.sol,Token721.sol,Token1155.sol). - Solidity tests:
contracts/tests/(Token20.t.sol,Token721.t.sol,Token1155.t.sol) andcontracts/Counter.t.sol. - Node.js tests:
test/*.ts. - Deployment modules:
ignition/modules/*.ts.