javascript - Hardhat compile error "Expected a value of type HttpNetworkConfig" - Stack Overflow

admin2025-04-09  1

I'm attempting to follow the NFT tutorial here. I have set up the accounts on Alchemy and Metamask created the .sol file. I have a .env file in root that looks like this:

API_URL = ";
PRIVATE_KEY = "your-metamask-private-key"

My hardhat config file looks like this:

/**

* @type import('hardhat/config').HardhatUserConfig

*/

require('dotenv').config();

require("@nomiclabs/hardhat-ethers");

const { API_URL, PRIVATE_KEY } = process.env;

module.exports = {

   solidity: {
      pilers: [
        {
          version: "0.5.7"
        },
        {
          version: "0.8.0"
        },
        {
          version: "0.6.12"
        }
      ]
    },

   defaultNetwork: "ropsten",

   networks: {

      hardhat: {},

      ropsten: {

         url: API_KEY,

         accounts: [`0x${PRIVATE_KEY}`]

      }

   },

}

However when I try to pile I keep getting this error:

Invalid value {"url":";,"accounts":["0xyour-metamask-private-key"]} for HardhatConfigworks.ropsten - Expected a value of type HttpNetworkConfig.

I cannot seem to figure out why this is not a valid value for HttpNetworkConfig. What I have where url is a string and accounts is an array would appear to ply with what is in the documentation for network configs. It's a pile error so it would seem it cannot be a problem with the actual url or private key, but maybe I'm wrong about that. I willingly admit to being a noob here with only a cursory understanding of hardhat, solidity, and even js, etc. Any help appreciated.

I'm attempting to follow the NFT tutorial here. I have set up the accounts on Alchemy and Metamask created the .sol file. I have a .env file in root that looks like this:

API_URL = "https://eth-ropsten.alchemyapi.io/v2/your-api-key"
PRIVATE_KEY = "your-metamask-private-key"

My hardhat config file looks like this:

/**

* @type import('hardhat/config').HardhatUserConfig

*/

require('dotenv').config();

require("@nomiclabs/hardhat-ethers");

const { API_URL, PRIVATE_KEY } = process.env;

module.exports = {

   solidity: {
      pilers: [
        {
          version: "0.5.7"
        },
        {
          version: "0.8.0"
        },
        {
          version: "0.6.12"
        }
      ]
    },

   defaultNetwork: "ropsten",

   networks: {

      hardhat: {},

      ropsten: {

         url: API_KEY,

         accounts: [`0x${PRIVATE_KEY}`]

      }

   },

}

However when I try to pile I keep getting this error:

Invalid value {"url":"https://eth-ropsten.alchemyapi.io/v2/your-api-key","accounts":["0xyour-metamask-private-key"]} for HardhatConfigworks.ropsten - Expected a value of type HttpNetworkConfig.

I cannot seem to figure out why this is not a valid value for HttpNetworkConfig. What I have where url is a string and accounts is an array would appear to ply with what is in the documentation for network configs. It's a pile error so it would seem it cannot be a problem with the actual url or private key, but maybe I'm wrong about that. I willingly admit to being a noob here with only a cursory understanding of hardhat, solidity, and even js, etc. Any help appreciated.

Share Improve this question asked Sep 24, 2021 at 16:36 user3055034user3055034 6531 gold badge7 silver badges15 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

Turns out, the problem was with my private key. Check carefully.

You are probably working at localhost:8545. I think the issue is the value of the assets and some accounts used in your context exist on the mainnet. To solve this problem, you need to hardfork the mainnet to your local.

Please check this guide. https://hardhat/hardhat-network/guides/mainnet-forking.html

I was not setting my privateKey to the accounts element.

Turns out I was missing a value for my LIVE_PRIVATE_KEY as I also had a DEV_PRIVATE_KEY

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744203085a235893.html

最新回复(0)