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

编程入门 行业动态 更新时间:2024-10-02 18:33:07

为什么我会收到此错误:HardhatError: HH8:?如果<a href=https://www.elefans.com/category/jswz/34/1771200.html style=我不使用 .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.
回答如下:

更多推荐

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

本文发布于:2024-05-30 13:37:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770553.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我不   我会   它为   错误   env

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!