首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Error HH8:配置文件中有一个或多个错误,预期值为HttpNetworkConfig类型

Error HH8:配置文件中有一个或多个错误,预期值为HttpNetworkConfig类型
EN

Ethereum用户
提问于 2021-10-17 19:29:41
回答 6查看 9K关注 0票数 3

为什么硬帽子扔错了?我复制n从https://hardhat.org/config/粘贴默认配置文件?

代码语言:javascript
复制
*Error HH8: There's one or more errors in your config file:
 Invalid value {"url":"https://eth-rinkeby.alchemyapi.io/v2/xxxxxxxxxx","accounts":[null]} for HardhatConfig.networks.rinkeby - Expected a value of type HttpNetworkConfig.*

To learn more about Hardhat's configuration, please go to https://hardhat.org/config/
代码语言:javascript
复制
/**
 * @type import('hardhat/config').HardhatUserConfig
 */
require("@nomiclabs/hardhat-waffle");
require("@nomiclabs/hardhat-ethers");
require("@nomiclabs/hardhat-truffle5");
require("@nomiclabs/hardhat-etherscan");
require("hardhat-deploy");

require("dotenv").config();

const privateKey1 = process.env.PRIVATE_KEY;
const etherscanKey = process.env.ETHERSCAN_API_KEY;

module.exports = {
  defaultNetwork: "rinkeby",
  networks: {
    hardhat: {},
    rinkeby: {
      url: "https://eth-rinkeby.alchemyapi.io/v2/oL89FHmvkiWEfUgdjWON4NZBnB-497Is",
      accounts: [privateKey1],
    },
  },
  solidity: {
    version: "0.8.0",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200,
      },
    },
  },
  paths: {
    sources: "./contracts",
    tests: "./test",
    cache: "./cache",
    artifacts: "./artifacts",
  },
  mocha: {
    timeout: 20000,
  },
};
EN

回答 6

Ethereum用户

回答已采纳

发布于 2021-10-18 17:11:42

必须运行source .env才能在Ubuntu20.04LTS中启用.env

票数 4
EN

Ethereum用户

发布于 2021-11-08 22:07:26

您将得到此错误,因为“硬帽子”需要能够验证用于网络的URL和帐户对于该网络是否有效。在您的具体情况下,您的私钥不起作用。

解决以下问题的两种方法:

1.删除不需要

的网络

在您的hardhat.config.js中,您可以注释掉或删除正在出错的网络。你的错误是:

代码语言:javascript
复制
Invalid value {"url":"https://eth-rinkeby.alchemyapi.io/v2/xxxxxxxxxx","accounts":[null]} for HardhatConfig.networks.rinkeby - Expected a value of type HttpNetworkConfig.*

因此,它正在查看rinkeby网址,而不是找到一个“好的”URL。将网络配置更改为:

代码语言:javascript
复制
        // rinkeby: {
        //     url: "https://eth-rinkeby.alchemyapi.io/v2/oL89FHmvkiWEfUgdjWON4NZBnB-497Is",
        //     accounts: [privateKey1],
        //   },

2.修复变量

您需要确保您的环境变量实际上是正确的。做console.log(process.env.PRIVATE_KEY)console.log(process.env.RINKEBY_RPC_URL)是检查的方法。或者,如果您在linux中,运行echo $PRIVATE_KEY

一旦所有变量都正常工作,配置就会正常工作。

票数 3
EN

Ethereum用户

发布于 2021-11-24 16:11:41

我遇到这个问题是因为我没有导入dotenv配置。您可以通过在hardhat.config.js中添加这一行来做到这一点:

代码语言:javascript
复制
require('dotenv').config();

注意: OP确实添加了这一行,但是这个解决方案是针对忘记导入它的人的。

票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/111731

复制
相关文章

相似问题

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