Hardhat 2 Integration
Build a Hardhat 2 project from scratch, configure it for Cronos EVM, and deploy a sample contract with Hardhat Ignition.
Hardhat 2 is the previous major version of Hardhat. Use it if you're maintaining an existing Hardhat 2 project; for new work, start with Hardhat 3.
Prerequisites
Node.js 20, 22 or 24
A wallet private key: With a small amount of CRO to pay for gas fees. (For testnet TCRO, use the faucet at https://faucet.cronos.com/.)
An RPC endpoint: See details here.
Step 1. Create and initialize the project
mkdir my-cronos-project
cd my-cronos-project
npm init -y
npm install --save-dev hardhat@^2.29.0
npx hardhat initnpx hardhat init starts the setup wizard. Choose Create a TypeScript project , and accept the suggested dependencies.
Step 2. Write your contract
The wizard created a sample contract at contracts/Lock.sol . You can remove it and add your contracts to contracts/.
Step 2.1. Install Dependencies
hardhat-toolbox bundles ethers v6, chai matchers, TypeChain, the gas reporter and the hardhat verify task.
Step 3. Configure .env
Hardhat 2 has no keystore, so use a .env file loaded by dotenv:
.env holds your private key in plain text. Never commit it, and never use a mainnet key that holds meaningful funds for day-to-day development.
Step 4. Configure Cronos
Replace the generated hardhat.config.ts with this. It defines both Cronos networks and both explorers.
Confirm the config connects:
Step 5. Compile
This also generates TypeChain types under typechain-types/, which the tests and deploy scripts import.
Step 6. Test
The wizard created a sample script at test/Lock.ts folder, to run it:
Step 7. Deploy
Use hardhat ignition to deploy the contract:
To deploy to mainnet, swap --network cronosTestnet for --network cronos.
Step 8. Verify
In your terminal:
Last updated
Was this helpful?