This project demonstrates a basic Hardhat use case configured for Monad. It comes with a sample contract, a test for that contract, and a Hardhat Ignition module that deploys that contract.
hardhat-monad/
├── contracts/ # Smart contract source files
│ └── Counter.sol # Simple counter contract (no constructor params)
├── ignition/ # Hardhat Ignition deployment modules
│ └── modules/
│ └── Counter.ts # Deployment configuration for Counter contract
├── .env.example # Example environment variables file
├── hardhat.config.ts # Hardhat configuration
├── package.json # Project dependencies
└── tsconfig.json # TypeScript configuration
- Node.js (v16+)
-
Clone this repository:
git clone https://github.com/monad-developers/hardhat-monad.git cd hardhat-monad -
Install dependencies:
npm install
-
Create a
.envfile based on.env.example:cp .env.example .env
-
Add your private key and Etherscan API key to the
.envfile:PRIVATE_KEY=your_private_key_here ETHERSCAN_API_KEY=your_etherscan_api_key_here⚠️ IMPORTANT: Never commit your.envfile or expose your private key.
Run tests with Hardhat:
npx hardhat testThis project uses Hardhat Ignition for deployments, which makes it easy to manage complex deployment procedures.
To deploy the contract to a local hardhat node, first start the node:
npx hardhat nodeThen deploy:
npx hardhat ignition deploy ignition/modules/Counter.tsTo deploy to Monad Testnet, you need an account with funds. Make sure you have set your private key in the .env file:
npx hardhat ignition deploy ignition/modules/Counter.ts --network monadTestnetTo redeploy to a different address:
npx hardhat ignition deploy ignition/modules/Counter.ts --network monadTestnet --resetTo verify the deployed contract on Monad Testnet (uses Sourcify and MonadScan):
npx hardhat verify <CONTRACT_ADDRESS> --network monadTestnetNote: The verification command may show an error message, but this is often misleading - the contract is usually verified successfully on both Sourcify and MonadScan. Check the explorer links to confirm verification.
To deploy to Monad Mainnet, ensure you have set your private key in the .env file:
npx hardhat ignition deploy ignition/modules/Counter.ts --network monadMainnetTo redeploy to a different address:
npx hardhat ignition deploy ignition/modules/Counter.ts --network monadMainnet --resetTo verify the deployed contract on Monad Mainnet (uses Sourcify and MonadScan):
npx hardhat verify <CONTRACT_ADDRESS> --network monadMainnetNote: The verification command may show an error message, but this is often misleading - the contract is usually verified successfully on both Sourcify and MonadScan. Check the explorer links to confirm verification.
Once verified, you can view your contract on:
- MonadVision (Sourcify)
- MonadScan (Etherscan)
The sample Counter contract includes:
inc()- Increment counter by 1incBy(uint)- Increment counter by a specified amountx- Public variable to read the current count
- Refer to docs.monad.xyz for Monad-specific documentation
- Visit Hardhat Documentation for Hardhat help
- Check Hardhat Ignition Guide for deployment assistance
This project is licensed under the MIT License.