Hardhat compile error "Expected a value of type HttpNetworkConfig"
Asked Answered
Z

4

6

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: {
      compilers: [
        {
          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 compile I keep getting this error:

Invalid value {"url":"https://eth-ropsten.alchemyapi.io/v2/your-api-key","accounts":["0xyour-metamask-private-key"]} for HardhatConfig.networks.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 comply with what is in the documentation for network configs. It's a compile 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.

Zeralda answered 24/9, 2021 at 16:36 Comment(0)
Z
3

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

Zeralda answered 30/9, 2021 at 4:59 Comment(0)
C
0

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.org/hardhat-network/guides/mainnet-forking.html

Channing answered 7/10, 2021 at 18:49 Comment(0)
S
0

I was not setting my privateKey to the accounts element.

Slone answered 1/3, 2022 at 21:8 Comment(0)
L
0

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

Lemos answered 20/4, 2022 at 20:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.