最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

为什么我会收到此错误:HardhatError: HH8:?如果我不使用 .env,它为什么会消失?

网站源码admin34浏览0评论

为什么我会收到此错误:HardhatError: HH8:?如果我不使用 .env,它为什么会消失?

为什么我会收到此错误:HardhatError: HH8:?如果我不使用 .env,它为什么会消失?

我正在学习 solidity hardhat 教程。学习将合约部署到 sepolia 测试网。

当我使用环境变量提供网络详细信息时显示错误。如果我直接提供详细信息,我会部署合约。

hardhat.config.js



require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();

const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL;
const SEPOLIA_PVT_KEY = process.env.SEPOLIA_PVT_KEY;
const SEPOLIA_CHAIN_ID = process.env.SEPOLIA_CHAIN_ID;

// commented section is working
// const SEPOLIA_RPC_URL =
//     "";
// const SEPOLIA_PVT_KEY =
//     "***********************************************************";
// const SEPOLIA_CHAIN_ID = 11155111;
module.exports = {
    defaultNetwork: "hardhat",
    networks: {
        sepolia: {
            url: SEPOLIA_RPC_URL,
            accounts: [SEPOLIA_PVT_KEY],
            chainId: SEPOLIA_CHAIN_ID,
        },
    },
    solidity: "0.8.18",
};

task("accounts", "Prints the list of accounts", async () => {
    const accounts = await ethers.getSigners();

    for (const account of accounts) {
        console.log(account.address);
    }
});

.env

SEPOLIA_RPC_URL=
SEPOLIA_PVT_KEY=***************************************************************
SEPOLIA_CHAIN_ID=11155111

error
使用环境变量时

blue@DESKTOP-A6GBG6O:~/solidity/hardhat-sss$ yarn hardhat run scripts/deploy.js --network sepolia
yarn run v1.22.19
$ /home/blue/solidity/hardhat-sss/node_modules/.bin/hardhat run scripts/deploy.js --network sepolia
Error HH8: There's one or more errors in your config file:

  * Invalid value {"url":"",
"accounts":["************************************************************"],"chainId":"11155111"} 
for HardhatConfigworks.sepolia - Expected a value of type HttpNetworkConfig.
回答如下:
发布评论

评论列表(0)

  1. 暂无评论