0

MY hardhat.config.js

require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
require("@nomiclabs/hardhat-etherscan");
const Goerli_RPC_URL = process.env.RINKEBY_RPC_URL;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const ETHERSCAN_API = process.env.ETHERSCAN_API;
console.log(Goerli_RPC_URL);
console.log(PRIVATE_KEY);
console.log(ETHERSCAN_API );
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: "0.8.9",
  networks:{
    Goerli:{
      url:Goerli_RPC_URL,
      chainId:420,
      accounts:[PRIVATE_KEY],
    },
    etherscan:{
      apiKey:ETHERSCAN_API,
    }
  },
};

error in the terminal .....

Error HH8: There's one or more errors in your config file:

  * Invalid value undefined for HardhatConfig.networks.Goerli.url - Expected a value of type string.   
  * Invalid value undefined for HardhatConfig.networks.etherscan.url - Expected a value of type string.  
To learn more about Hardhat's configuration, please go to https://hardhat.org/config/

For more info go to https://hardhat.org/HH8 or run Hardhat with --show-stack-traces

I was correctly getting my privatekey && etherscan url in console but my Goerli url was been shown as undefined and even when i typed npx hardhat i was getting this above err

MY deploy.js

const ethers = require("hardhat");
async function main()
{
  const contractfactory = await new ethers.contractFactory("Lock");
  console.log("deploying contract");
  const contract = await contractfactory.deploy(5);
  await contract.deployed();
  console.log(`the contract is deployed to : ${contract.address}`);
}
main().then(
  ()=> process.exit(0)
).catch(err => {
  console.error(err);
  process.exit(1);
})

2 Answers 2

0

In your config

etherscan:{
      apiKey:ETHERSCAN_API,
    }

placed into networks section

Fix this like that:

networks: {
    testnetMatic: {
        url: "https://rpc-mumbai.maticvigil.com/",
        chainId: 80001,
        gasPrice: 20000000000,
        accounts: { mnemonic: mnemonic }
    },
},
etherscan: {
    apiKey: <bscScanApiKey>
},
0

You did import dotenv in the hardhat.config.js but seems like you didn't do it in your deploy.js file. Importing dotenv in your deploy.js using

require("dotenv").config();

Should fix your problem. (It did fix mine!)

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.