This project showcases a Hardhat3 project using the native Node.js test runner (node:test) and the viem library for Monad Testnet interactions.
To learn more about Hardhat3, please visit the Getting Started guide. For support, see Hardhat's current Getting help guide, or open an issue to report a bug.
This example project includes:
- A simple Hardhat configuration file.
- Foundry-compatible Solidity unit tests.
- TypeScript integration tests using
node:test, the Node.js native test runner, andviem. - Monad Testnet and Mainnet network configuration.
Install the dependencies:
npm installLocal compilation and tests do not require a private key. Before deploying to Testnet or Mainnet, set the PRIVATE_KEY configuration variable. Before verifying a contract, also set ETHERSCAN_API_KEY.
Store the variables in the Hardhat keystore:
npx hardhat keystore set PRIVATE_KEY
npx hardhat keystore set ETHERSCAN_API_KEYAlternatively, copy .env.example to .env and fill in the values. The configuration loads this file through dotenv.
cp .env.example .envNever commit .env or expose a funded account's private key.
To run all the tests in the project, execute the following command:
npx hardhat testYou can also selectively run the Solidity or node:test tests:
npx hardhat test solidity
npx hardhat test nodejsThis project includes an example Ignition module to deploy the contract. You can deploy this module to a locally simulated chain, Monad Testnet, or Monad Mainnet.
Local deployment does not require configuration variables:
npx hardhat ignition deploy ignition/modules/Counter.tsSet PRIVATE_KEY to a funded Testnet account as described in Setup, then deploy:
npx hardhat ignition deploy ignition/modules/Counter.ts --network monadTestnetSet ETHERSCAN_API_KEY, then verify the deployed contract:
npx hardhat verify <CONTRACT_ADDRESS> --network monadTestnetSet PRIVATE_KEY to a funded Mainnet account, then deploy:
npx hardhat ignition deploy ignition/modules/Counter.ts --network monadMainnetSet ETHERSCAN_API_KEY, then verify the deployed contract:
npx hardhat verify <CONTRACT_ADDRESS> --network monadMainnet