Blueprints

Hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software. This guide describes how to configure Hardhat to deploy contracts on the IoTeX blockchain.

If you want to learn more about Hardhat and how to use it, please refer to the official documentation:

Hardhat Getting Started

We assume you have already created a project in Hardhat.

Configure Hardhat

You can configure hardhat deployment accounts using a mnemonic phrase, or by setting an array of private keys, which can be also input from the command line or set in the .env configuration file. As this is not the scope of this documentation, we refer you to the hardhat network configuration docs.

Configuration

To configure Hardhat to work with the Cipherem network, you need to update the hardhat.config.js file. Add the following configuration to define the Cipherem network:

require("@nomiclabs/hardhat-waffle");

module.exports = {
  solidity: "0.8.4",
  networks: {
    cipherem: {
      url: "https://network.cipherem.com",
      chainid: 292003,
      accounts: ["YOUR_PRIVATE_KEY"]
    }
  }
};

Replace "YOUR_PRIVATE_KEY" with your actual Cipherem account private key.

Writing and Compiling Smart Contracts

Create a new file in the contracts directory, for example, SimpleStorage.sol:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

contract SimpleStorage {
    uint256 public data;

    function set(uint256 _data) public {
        data = _data;
    }

    function get() public view returns (uint256) {
        return data;
    }
}

Compile the Smart Contract

Run the following command to compile your smart contract:

npx hardhat compile

Deploy the Smart Contract

npx hardhat run scripts/sample.js --network cipherem

Copyright © 2024