Deploy with Hardhat

Hardhat is one of the most popular development frameworks for building and deploying smart contracts on EVM-compatible chains. Omega's compatibility with the EVM makes deploying via Hardhat fast and simple.


πŸ“¦ Prerequisites

Make sure you have Node.js and npm installed.

Install Hardhat in your project directory:

npm init -y
npm install --save-dev hardhat
npx hardhat

Choose "Create a basic sample project" and follow the prompts.


πŸ”§ Configure for Omega

  1. Install dotenv and @nomicfoundation/hardhat-toolbox:

npm install dotenv
npm install --save-dev @nomicfoundation/hardhat-toolbox
  1. Update hardhat.config.js:

require('dotenv').config();
require('@nomicfoundation/hardhat-toolbox');

module.exports = {
  solidity: "0.8.20",
  networks: {
    omega: {
      url: process.env.RPC_URL,
      accounts: [process.env.PRIVATE_KEY],
      chainId: 1313161768
    }
  }
};
  1. Create a .env file:

RPC_URL=https://0x4e454228.rpc.aurora-cloud.dev
PRIVATE_KEY=your_private_key

✍️ Example: Simple Contract

Here's a basic contract you can use:

// contracts/Counter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract Counter {
    uint256 public count;

    function increment() public {
        count += 1;
    }
}

πŸš€ Deploy Script

Create scripts/deploy.js:

async function main() {
  const Counter = await ethers.getContractFactory("Counter");
  const counter = await Counter.deploy();
  await counter.deployed();
  console.log(`Counter deployed to: ${counter.address}`);
}

main()
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });

πŸ§ͺ Compile and Deploy

Compile:

npx hardhat compile

Deploy to Omega:

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

Last updated