Hardhat Configuration Error – Resolving Invalid Value Undefined for HardhatConfig.networks.rinkeby.url

hardhat

The code is:

require('@nomiclabs/hardhat-waffle')
require('dotenv').config({ path: '.env'})

const ALCHEMY_API_URL = process.env.ALCHEMY_API_URL
const RINKEBY_PRIVATE_KEY = process.env.RINKEBY_PRIVATE_KEY

module.exports = {
  solidity: '0.8.9',
  networks: {
    rinkeby: {
      url: ALCHEMY_API_URL,
      accounts: [RINKEBY_PRIVATE_KEY],
    },
  },
}

It shows following error while running – npx hardhat verify --network rinkeby in the terminal

 Invalid value undefined for HardhatConfig.networks.rinkeby.url - Expected a value of type string.
  * Invalid account: #0 for network: rinkeby - Expected string, received undefined

Best Answer

Don't give path inside config(), hardhat smart enough to know the files Change your line 2

require("dotenv").config()

Mine work after removing path..