0

I'm having error in my config file: Error HH8: There's one or more errors in your config file:

  * Invalid value undefined for HardhatConfig.networks.rinkeby.url - Expected a value of type string.
  * Invalid value {} for HardhatConfig.networks.rinkeby - Expected a value of type HttpNetworkHDAccountsConfig.
  * Invalid value undefined for HardhatConfig.networks.ropsten.url - Expected a value of type string.
  * Invalid value {} for HardhatConfig.networks.ropsten - Expected a value of type HttpNetworkHDAccountsConfig.
  * Invalid value {} for HardhatConfig.networks.ganache - Expected a value of type HttpNetworkHDAccountsConfig.
  * Invalid value undefined for HardhatConfig.networks.mainnet.url - Expected a value of type string.
  * Invalid value {} for HardhatConfig.networks.mainnet - Expected a value of type HttpNetworkHDAccountsConfig.
  * Invalid value {} for HardhatConfig.networks.polygon - Expected a value of type HttpNetworkHDAccountsConfig.
  
To learn more about Hardhat's configuration, please go to https://hardhat.org/config/

my config file:

require("@nomiclabs/hardhat-waffle");
require("@nomiclabs/hardhat-etherscan");


require('dotenv').config()

// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
  const accounts = await hre.ethers.getSigners();

  for (const account of accounts) {
    console.log(account.address);
  }
});
const MAINNET_RPC_URL = process.env.MAINNET_RPC_URL || process.env.ALCHEMY_MAINNET_RPC_URL
const RINKEBY_RPC_URL = process.env.RINKEBY_RPC_URL
const ROPSTEN_RPC_URL = process.env.ROPSTEN_RPC_URL
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY
const MNEMONIC = process.env.MNEMONIC
module.exports = {
  solidity: "0.8.4",
  networks: {
   

    rinkeby: {
      url: RINKEBY_RPC_URL,
      // accounts: [PRIVATE_KEY],
      accounts: {
        mnemonic: MNEMONIC,
      },
      saveDeployments: true,
    },
    ropsten: {
      url: ROPSTEN_RPC_URL,
      // accounts: [PRIVATE_KEY],
      accounts: {
        mnemonic: MNEMONIC,
      },
      saveDeployments: true,
    },
    ganache: {
      url: 'http://localhost:8545',
      accounts: {
        mnemonic: MNEMONIC,
      }
    },
    mainnet: {
      url: MAINNET_RPC_URL,
      // accounts: [PRIVATE_KEY],
      accounts: {
        mnemonic: MNEMONIC,
      },
      saveDeployments: true,
    },
    polygon: {
      url: "https://rpc-mainnet.maticvigil.com/",
      // accounts: [PRIVATE_KEY],
      accounts: {
        mnemonic: MNEMONIC,
      },
      saveDeployments: true,

    }
  },
  etherscan: {
    // Your API key for Etherscan
    // Obtain one at https://etherscan.io/
    apiKey: ETHERSCAN_API_KEY
  },
  mocha: {
    timeout: 100000
  }
};

I actually deployed a couple of times smart contracts to different networks with the config file above. Know I don't know what changed. Any ideas?

6
  • most likely the variables have value undefined. Print out their contents within the script. Mar 21, 2022 at 20:00
  • And how do I do that? You meant print the env var to see if they are really defined?
    – OmerS
    Mar 22, 2022 at 8:14
  • console.log('Here is rinkeby:', RINKEBY_RPC_URL); Mar 22, 2022 at 8:19
  • I see... so after doing that s appears that all my urls are undefined for some reason. I'll try and change that.
    – OmerS
    Mar 22, 2022 at 9:14
  • I can't get the process.env read from my .env file. What I did is like: RINKEBY_RPC_URL='rinkeby.infura.io/v3/continue_with_api_key' in the.env file and then reads with process.env.RINKEBY_RPC_URL I'm on windows if that's matter.
    – OmerS
    Mar 22, 2022 at 12:12

2 Answers 2

0

you are using what seems to be an env variable, so either you add as a prefix process.env (if these variables are defined in your .env) or you hardcode the "HTTP" addresses

an example for Rinkeby:

rinkeby: {
      url: process.env.RINKEBY_RPC_URL || "http://your-rinkeby-provider",
      accounts: {
        mnemonic: MNEMONIC,
      },
    },

Your .env should be looking like this:

   ETHERSCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1
   RINKEBY_RPC_URL=https://eth-rinkeby.alchemyapi.io/
   PRIVATE_KEY=0xabc123abc123abc123abc123abc123abc123abc123abc...

to access these variables you need to use process.env, process.env.RINKEBY_RPC_URL in your hardhat-config

10
  • yes I defined them as env var like: RINKEBY_RPC_URL='rinkeby.infura.io/apikeyHere' maybe I should add export at the beginning of each env var?
    – OmerS
    Mar 22, 2022 at 7:10
  • no you don't need
    – Adam Boudj
    Mar 22, 2022 at 9:04
  • I defined them just like that but as strings. It appears that I can't pull them for some reason with process.env.RINKEBY_RPC_URL for example. Do you have an idea?
    – OmerS
    Mar 22, 2022 at 9:18
  • by default you should have this import * as dotenv from "dotenv"; on your hardhat config, otherwise add it
    – Adam Boudj
    Mar 22, 2022 at 9:40
  • I'm importing it with commonjs like: require('dotenv').config() Is that enough? I understood that required is used by default with node.js, so all the import supposed to be with require.
    – OmerS
    Mar 22, 2022 at 10:13
0

Found the source of my problem. I used .gitignore file from pre-build .gitignore files folder on github- the node one (can see it here) probably ignored somthing I needed (don't know what exatcly).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.