首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用安全帽部署智能契约时出错--错误HH9:加载硬件配置时出错

使用安全帽部署智能契约时出错--错误HH9:加载硬件配置时出错
EN

Stack Overflow用户
提问于 2022-04-08 06:26:41
回答 2查看 2K关注 0票数 0

尝试使用“硬帽子”部署智能契约,但获得配置错误。

以下是完整的错误详细信息

代码语言:javascript
运行
复制
Error HH9: Error while loading Hardhat's configuration.
You probably tried to import the "hardhat" module from your config or a file imported from it.
This is not possible, as Hardhat can't be initialized while its config is being defined.

所有的插件似乎都已正确安装。

deploy.js

代码语言:javascript
运行
复制
const hre = require("hardhat");

async function main() {
  const TestContract = await hre.ethers.getContractFactory("TestContract");
  const superInstance = await TestContract.deploy("TestContractHAT", "SMC");
  await superInstance.deployed();
  console.log("contract was deployed to:", superInstance.address());
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

package.json

代码语言:javascript
运行
复制
{
  "name": "Test",
  "version": "1.0.0",
  "description": "This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts.",
  "main": "hardhat.config.js",
  "directories": {
    "test": "test"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@nomiclabs/hardhat-ethers": "^2.0.5",
    "@nomiclabs/hardhat-waffle": "^2.0.3",
    "chai": "^4.3.6",
    "ethereum-waffle": "^3.4.4",
    "ethers": "^5.6.2"
  },
  "dependencies": {
    "dotenv": "^16.0.0",
    "hardhat": "^2.9.3"
  }
}

Hardhat.config

代码语言:javascript
运行
复制
const { ethers } = require("hardhat");
require('@nomiclabs/hardhat-waffle');
require("@nomiclabs/hardhat-ethers");
require('@openzeppelin/hardhat-upgrades');


require("dotenv").config();
// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
  const accounts = await hre.ethers.getSigners();  
  for (const account of accounts) {
    console.log(account.address);
  }
});

// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more

/**
 * @type import('hardhat/config').HardhatUserConfig
 */
module.exports = {
  solidity: "0.8.2",
  networks: {
    mumbai: {
      url: process.env.MUMBAI_URL,
      account: process.env.PRIVATE_KEY
    }
  }
};

任何指示都是有帮助的。谢谢

EN

Stack Overflow用户

回答已采纳

发布于 2022-04-08 07:02:51

当错误状态出现时,您将在硬帽子配置中导入hardhat模块。

代码语言:javascript
运行
复制
You probably tried to import the "hardhat" module from your config or a file imported from it. This is not possible, as Hardhat can't be initialized while its config is being defined.

移除线

代码语言:javascript
运行
复制
const { ethers } = require("hardhat");

错误就会消失

票数 3
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71792535

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档