For the complete documentation index, see llms.txt. This page is also available as Markdown.

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.

Hardhat 2 is scheduled for formal End-of-Life (EOL) on June 1, 2027. However, this deprecation date will move even earlier if the Ethereum Hegota mainnet activation occurs before that date.

The Nomic Foundation has replaced Hardhat 2 with Hardhat 3, which is now stable and production-ready.

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 init

npx 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:

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?