'Hardhat compile error "Expected a value of type HttpNetworkConfig"
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.
Solution 1:[1]
Turns out, the problem was with my private key. Check carefully.
Solution 2:[2]
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
Solution 3:[3]
I was not setting my privateKey
to the accounts
element.
Solution 4:[4]
Turns out I was missing a value for my LIVE_PRIVATE_KEY
as I also had a DEV_PRIVATE_KEY
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | user3055034 |
Solution 2 | DreH-World |
Solution 3 | Evandro Pomatti |
Solution 4 | nolanjacobson |