1
require('dotenv').config();
require('@nomicfoundation/hardhat-toolbox');

const API_URL = process.env.API_URL;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const API_KEY=process.env.API_KEY

console.log("API_URL:", API_URL);
console.log("PRIVATE_KEY:", PRIVATE_KEY);
console.log("API_KEY:", API_KEY);
module.exports = {
  solidity: "0.8.18",
  networks: {
    goerli: {
      url: API_URL,
      accounts: [PRIVATE_KEY],
      alchemy: API_KEY
    },
  },
};

when i run npx hardhat run ./scripts/deploy.js it deploys successfully but when I run via goerli npx hardhat run ./scripts/deploy --network goerli I am getting error HH601: Script ./scripts/deploy doesn't exist.

2 Answers 2

0

I can find 2 mistakes in your attempts.

first in your hardhat.config.js it should be

goerli: {
  url: API_URL, //(this should contain the key already)
  accounts:PRIVATE_KEY,
},

secondly: it should be npx hardhat run scripts/deploy.js --network goerli whereas you have: npx hardhat run ./scripts/deploy --network goerli

I hope this helps, anything just ask

5
  • Thnaks for reply now i am getting could not detect network (event="noNetwork", code=NETWORK_ERROR, error Mar 26 at 5:56
  • Did you erase networks?
    – Barrocz
    Mar 27 at 21:37
  • networks: { goerli: { url: API_URL, //(this should contain the key already) accounts:PRIVATE_KEY, }, },
    – Barrocz
    Mar 27 at 21:38
  • no network is there Mar 28 at 13:57
  • Man, I found the answer. you have to add the path inside require('dotenv').config(HERE); For example: require("dotenv").config({ path: ".env" });
    – Barrocz
    Mar 29 at 10:37
0

I think that what is going on is that the goerli object has the url and the key in two separate keys. You don't have this error when you use the local hardhat node because this object never gets evaluated. Here is an example on how to put together the URL and the KEY for infura:

networks: {
        goerli: {
          url: `https://goerli.infura.io/v3/${API_KEY}`,
          accounts: [PRIVATE_KEY],
        },
},
1
  • Thnaks for reply now i am getting could not detect network (event="noNetwork", code=NETWORK_ERROR, error Mar 26 at 5:55

Your Answer

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

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