I am currently trying to deploy my DApp 'nftmarketplace' to the net using Vercel on the Goerli test network. However the app is failing to connect to the blockchain and I am getting the following error:

Uncaught (in promise) Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.6.8)

Here is my hardhat config:

const fs = require('fs');

const privateKey = fs.readFileSync('.secret').toString().trim();

module.exports = {
  networks: {
    goerli: {
      url: 'https://eth-goerli.g.alchemy.com/v2/UNfhfGfQ9lrSjTGUS_X-BM-G0_lMEVh9',
      accounts: [privateKey],
  solidity: '0.8.4',

Can someone please let me know how to fix this issue?

Here is the link to the github repo if you need that:


2 Answers 2


That configuration fairly look complex. Instead of 'fs' you can simply use .env file.

First install, dotenv

Next create .env file.

Inside the file, the values should be like this.

ALCHEMY_API_KEY = "*******"

Next set the configuration file like this:


const { GOERLI_PRIVATE_KEY, ALCHEMY_API_KEY } = process.env;

module.exports = {
  solidity: "0.8.9",
  networks: {
    goerli: {
      url: `https://eth-goerli.alchemyapi.io/v2/${ALCHEMY_API_KEY}`,
      accounts: [GOERLI_PRIVATE_KEY],

Also your network url is wrong. There shouldn't be .g in the url. You can copy paste mine for the future references.

Tell me if it helps!


So I happened to encounter the same problem as you when I configured new network. Here I was thinking what was the problem, I have configured everything right right?.

Apparently, the problem is not within the url. My URL works correct. And the problem lies in .env file.

Usually the hardhat folder structure is like this:

└── APP
    ├── contracts
    │   ├── contract1.sol
    │   └── contract2.sol
    ├── Scripts
    │   ├── 1_contract1.js
    │   └── 2_contract2.js
    ├── tests
    ├── .env
    ├── hardhat.config.json
    └── package.json

When I am running the 1_contract1.js from inside the scripts folder, I am getting the network not found error.

But when I am running the same file from the root folder that is app according to the diagram, it works.

Like this:

npx hardhat run scripts/1.contract1.js

So problem lies in from where you are running the script file. So try to run from the root folder.

Also if it doesn't work, please share your new configuration file.

  • Thanks for your help, will implement it when I have the chance and let you know if it fixes the problem :) Sep 21, 2022 at 5:48
  • I implemented your solution however I am still facing the exact same error message Sep 22, 2022 at 0:23
  • Can you show your implementation once? I cannot say what is wrong without seeing.
    – Ad-h0c
    Sep 23, 2022 at 8:00
  • I think I figured out the problem. Check the edited section of the answer.
    – Ad-h0c
    Sep 23, 2022 at 8:10

The issue on my end was that I was using an old Alchemy API key.

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.