Blueprints

Hardhat

Hardhat 是一个用于编译、部署、测试和调试以太坊软件的开发环境。本指南介绍了如何配置 Hardhat 以在 Cipherem 区块链上部署合同。

如果您想了解更多关于 Hardhat 的信息以及如何使用它,请参阅官方文档:

Hardhat 入门

我们假设您已经在Hardhat中创建了一个项目。

配置 Hardhat

您可以使用助记短语或通过设置私钥数组来配置 Hardhat 部署帐户,私钥数组也可以从命令行输入或在 .env 配置文件中设置。由于这不是本文档的介绍范围,我们建议您参考 hardhat 网络配置文档。

配置

要配置 Hardhat 为与 Cipherem 网络协同工作,您需要更新 hardhat.config.js 文件。添加以下配置以定义 Cipherem 网络:

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

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

将 “YOUR_PRIVATE_KEY” 替换为您的实际 Cipherem 帐户私钥。

编写和编译智能合约

在 contracts 目录中创建一个新文件,例如 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;
    }
}

编译智能合约

运行以下命令以编译智能合约:

npx hardhat compile

部署智能合约

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

Copyright © 2024