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

Hardhat 3 Integration

Build a Hardhat 3 project from scratch, configure it for Cronos EVM, and deploy a sample contract with Hardhat Ignition.

Hardhat 3

Hardhat 3 is the recommended toolchain for new Cronos projects. It uses Hardhat Ignition for declarative deploymentsand an encrypted keystore so your private key never touches a file in your repo, and it lets you pick your test stack at init time — viem with node:test, or Mocha with Ethers.js.

Prerequisites

  • Node.js 22.13.0 or later

  • 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.

  • A Cronos Explorer API key, see how to obtain it here.

Step 1. Create and initialize the project

npx hardhat --init

--init is an interactive wizard. Choose:

  • Where would you like to initialize the project? -> Your project path, for example my-cronos-project

  • What type of project? → A TypeScript Hardhat project using Node Test Runner and Viem or A TypeScript Hardhat project using Mocha and Ethers.js .

  • Accept the suggested package.json and dependency install.

Step 2. Write your contract

The wizard writes a sample Counter contract at my-cronos-project/contracts/Counter.sol . You can remove it and add your contracts to my-cronos-project/contracts/.

Step 2.1. Install Dependencies

For example, to add OpenZeppelin as a dependency:

Step 3. Store your secrets

Hardhat 3 ships an encrypted keystore. Use it instead of a .env file. The value is stored outside your project, encrypted with a password you choose.

You will be prompted for a keystore password (first time only) and then for the value. Useful companions:

Step 4. Configure Cronos Network

In your hardhat.config.ts config Cronos networks:

Step 5. Compile

Step 6. Test

The wizard created a sample test contract at my-cronos-project/contracts/Counter.t.sol , and a sample test script at my-cronos-project/test/Counter.ts :

  • contract/Counter.t.sol: Written in Solidity. It runs directly on the Ethereum Virtual Machine (EVM) using Foundry (Forge).

  • test/Counter.ts: Written in TypeScript. It runs in a Node.js environment.

Check the differences between two test approaches at Hardhat 3 document.

To run all the tests:

To run each type of test:

Step 7. Deploy

Hardhat 3 deploys through Ignition modules — declarative descriptions of what to deploy, so re-running a deployment resumes instead of duplicating.

The wizard created a sample at ignition/modules/Counter.ts . To run the script:

Ignition prints the deployed address on success. To deploy to mainnet, swap --network cronosTestnet for --network cronos.

Step 8. Verify

hardhat-verify is already included as part of the template project. If you want to add the plugin manually:

In your hardhat.config.ts add:

In your terminal:

This command will verify the contract in both Cronos Explorer and Sourcify, to verify it only in Cronos Explorer:

Or add below config to hardhat.config.ts :

Alternatively, you can deploy and verify the contract in a single command:

To verify the contract in mainnet, swap --network cronosTestnet for --network cronos.

Last updated

Was this helpful?