为什么硬帽子扔错了?我复制n从https://hardhat.org/config/粘贴默认配置文件?
*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//**
* @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,
},
};发布于 2021-10-18 17:11:42
必须运行source .env才能在Ubuntu20.04LTS中启用.env
发布于 2021-11-08 22:07:26
您将得到此错误,因为“硬帽子”需要能够验证用于网络的URL和帐户对于该网络是否有效。在您的具体情况下,您的私钥不起作用。
解决以下问题的两种方法:
的网络
在您的hardhat.config.js中,您可以注释掉或删除正在出错的网络。你的错误是:
Invalid value {"url":"https://eth-rinkeby.alchemyapi.io/v2/xxxxxxxxxx","accounts":[null]} for HardhatConfig.networks.rinkeby - Expected a value of type HttpNetworkConfig.*因此,它正在查看rinkeby网址,而不是找到一个“好的”URL。将网络配置更改为:
// rinkeby: {
// url: "https://eth-rinkeby.alchemyapi.io/v2/oL89FHmvkiWEfUgdjWON4NZBnB-497Is",
// accounts: [privateKey1],
// },您需要确保您的环境变量实际上是正确的。做console.log(process.env.PRIVATE_KEY)和console.log(process.env.RINKEBY_RPC_URL)是检查的方法。或者,如果您在linux中,运行echo $PRIVATE_KEY。
一旦所有变量都正常工作,配置就会正常工作。
发布于 2021-11-24 16:11:41
我遇到这个问题是因为我没有导入dotenv配置。您可以通过在hardhat.config.js中添加这一行来做到这一点:
require('dotenv').config();注意: OP确实添加了这一行,但是这个解决方案是针对忘记导入它的人的。
https://ethereum.stackexchange.com/questions/111731
复制相似问题