Smart contracts

Smart contracts on Cronos

Learn how to configure your tools, write basic Solidity contracts and deploy them to Cronos testnet and mainnet.

EVM Solidity Developers

Overview

Cronos is fully EVM-compatible, which means Solidity contracts, ABI encoding, gas behaviour and tooling work the same way as on Ethereum. The main differences come from network parameters (RPC endpoints, chain IDs), as well as the surrounding ecosystem your contract ultimately interacts with.

This page walks through a minimal but production-ready workflow using Hardhat. It is suitable both for newcomers and for teams planning to deploy more advanced applications on Cronos.

If you want a deeper understanding of nodes, execution layers and how Cronos handles EVM calls, visit the Architecture section.

Environment setup

Before writing contracts, make sure you have the essential tools installed:

  • Node.js (LTS), npm or yarn.
  • Git and a code editor such as VS Code.
  • A wallet configured for Cronos testnet with some test tokens.

Create a new Hardhat project

  1. Create a new project folder and open it in your terminal.
  2. Initialise a package.json:
    npm init -y
  3. Install Hardhat and useful plugins:
    npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox dotenv
  4. Initialise Hardhat:
    npx hardhat
    Choose “Create a basic sample project” when prompted.

Add Cronos networks to Hardhat

Update hardhat.config.js to include Cronos testnet and mainnet:

hardhat.config.js
require("dotenv").config(); require("@nomicfoundation/hardhat-toolbox"); module.exports = { solidity: "0.8.21", networks: { cronosTestnet: { url: "https://evm-t3.cronos.org", chainId: 338, accounts: [process.env.PRIVATE_KEY] }, cronosMainnet: { url: "https://evm.cronos.org", chainId: 25, accounts: [process.env.PRIVATE_KEY] } } };

Store your private key securely in a local .env file: PRIVATE_KEY=<your-private-key>. Never commit this file to Git. A dedicated “deployment wallet” is strongly recommended.

Tip Use a wallet separate from your main account for deployments. This reduces your exposure if a key leaks or a misconfigured script is executed.

Example contract

Below is a minimal counter contract. While simple, it demonstrates constructor parameters, events, state reads, restricted writes, and how to structure basic deployment scripts.

contracts/CronosCounter.sol
pragma solidity ^0.8.21; contract CronosCounter { uint256 private _value; address public immutable owner; event ValueChanged(uint256 newValue); constructor(uint256 initialValue) { owner = msg.sender; _value = initialValue; emit ValueChanged(initialValue); } function current() external view returns (uint256) { return _value; } function set(uint256 newValue) external { require(msg.sender == owner, "Only owner can set value"); _value = newValue; emit ValueChanged(newValue); } function increment() external { require(msg.sender == owner, "Only owner can increment"); _value += 1; emit ValueChanged(_value); } }

Deployment script

Create a basic deployment script that compiles the contract and prints its deployed address:

scripts/deploy.js
const hre = require("hardhat"); async function main() { const Counter = await hre.ethers.getContractFactory("CronosCounter"); const counter = await Counter.deploy(0); await counter.deployed(); console.log("CronosCounter deployed to:", counter.address); } main().catch((error) => { console.error(error); process.exitCode = 1; });

Deploy to Cronos

Deploy to Cronos testnet

  1. Ensure your deployer account has testnet tokens.
  2. Compile your contracts:
    npx hardhat compile
  3. Deploy with the testnet configuration:
    npx hardhat run scripts/deploy.js --network cronosTestnet
  4. Save your contract address — you’ll need it for front-end integration or further testing.

After deployment, you can extend the project with scripts, tests, or a front-end. If you're building a UI, see Developer tutorials & resources for examples of how to integrate Ethers.js or wagmi.

Deploy to Cronos mainnet

The mainnet deployment command is identical, except you switch networks:

npx hardhat run scripts/deploy.js --network cronosMainnet

Before deploying production contracts, always ensure:

  • Your code and constructor parameters have been reviewed.
  • You have full test coverage for key behaviours.
  • The contract was deployed and tested on testnet first.

Next steps & best practices

  • Add automated tests using Hardhat’s built-in test environment to verify state transitions and access control.
  • Apply common Solidity patterns such as role-based permissions, pausing and upgrade-safe storage if relevant.
  • Review Architecture to understand how Cronos nodes process transactions and blocks.
  • Explore real-world examples and front-end integrations in Developer tutorials & resources.
  • If you're new to the ecosystem, the Getting started section provides a broader introduction.