Hardhat Guide Setup & Workflows

A guide to setting up and using the Hardhat development environment for building, testing, and deploying on Ontomir EVM.

Hardhat is a flexible and extensible Ethereum development environment that is fully compatible with Ontomir EVM. It's an excellent choice for teams with JavaScript/TypeScript expertise or those who need complex deployment and testing workflows.

Project Setup and Configuration

Initialize and configure a new Hardhat project for Ontomir EVM development.

1. Installation

mkdir Ontomir-evm-hardhat
cd Ontomir-evm-hardhat
npm init -y
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox @openzeppelin/contracts
npx hardhat init # Select "Create a TypeScript project"

2. Configuration

Modify hardhat.config.ts to include networks and settings for Ontomir EVM.

import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "dotenv/config";

const config: HardhatUserConfig = {
  solidity: {
    version: "0.8.24",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200,
      },
      evmVersion: "istanbul"
    },
  },
  networks: {
    local: {
      url: "http://127.0.0.1:8545",
      chainId: 4321, // Your EVM chain ID
      accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],
      gasPrice: 20000000000,
    },
    testnet: {
      url: "<evm_rpc_url>",
      chainId: 4321, // Your EVM chain ID
      accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],
    }
  },
  gasReporter: {
    enabled: process.env.REPORT_GAS !== undefined,
    currency: "USD",
  },
  etherscan: {
    apiKey: {
      OntomirEvmTestnet: process.env.ETHERSCAN_API_KEY || "dummy_key"
    },
    customChains: [
      {
        network: "OntomirEvmTestnet",
        chainId: 4321, // Your EVM chain ID
        urls: {
          apiURL: "",
          browserURL: ""
        }
      }
    ]
  }
};

export default config;

TypeScript Integration

Hardhat's first-class TypeScript support enables type-safe contract interactions and tests.

1. Writing a Contract

Create a contract in the contracts/ directory. For this example, we'll use a simple LiquidStakingVault.

2. Writing Tests

Create type-safe tests in the test/ directory.

Run your tests:

Deployment Scripts

Create a deployment script in the scripts/ directory to deploy your contract to a live network.

Run the deployment script: