Home > Software engineering >  Network goerli doesn’t exist
Network goerli doesn’t exist

Time:11-04

When I try to deploy my deploy.js script it give messages “Network goerli doesn’t exist”

require("@nomicfoundation/hardhat-waffle")



module.exports = {
    solidity: {
        compilers: [{ version: "0.8.8" }, { version: "0.6.6" }]
    },
    defaultNetwork: "hardhat",
    namedAccounts: {
        deployer: {
            default: 0 //here this will by default take the first account as deployer
        }
    },
    network: {
        goerli: {
            url: GOERLI_RPC_URL,
            accounts: [PRIVATE_KEY],
            chainId: 5,
            blockConfirmation: 6
        }
    }
}

I tried to deploy the script an I kept getting error messages

CodePudding user response:

//Add API Key and Private Keys

require("@nomicfoundation/hardhat toolbox")
require("dotenv").config()
require("hardhat-deploy")

/** @type import('hardhat/config').HardhatUserConfig */
/** @type   import('hardhat/config').HardhatUserConfig    */

const GOERLI_PRIVATE_KEY = “PRIVATE_KEY”; const ETHERSCAN_API_KEY = “API_KEY”;

CodePudding user response:

I think I get it, have you tried with this configuration to Deploy? That is working to me!

Backup all files and folders in your project folder.

Delete all files and folders in your project folder, and rewrite npm command.

  npm init

Generate package.json file in your folder.

  npm install --save-dev hardhat @nomiclabs/hardhat-ethers "ethers@^5.0.0"

Choose (Create an empty hardhat.config.js)

Now your project have hardhat installed, create a copy of all folders in a backup folder, and all the solidity code to your project folder (if you have artifacts and cache folder don't copy it).

hardhat.config.js

/* Paste on the top of the file */
require('@nomiclabs/hardhat-ethers')
const API_URL = "Your testnet rpc link";
const PRIVATE_KEY = "Your Private Accout address"
const PUBLIC_KEY = "Your Account Address";
and in module.module export code here.

module.exports = {
  solidity: "0.8.0",
  defaultNetwork: "yourtestnetname",
  networks: {
    hardhat:{},
    yourtestnetname:{
      url: API_URL,
      accounts: [`0x${PRIVATE_KEY}`]
    }
  }
};

Check 0x${} for sure it in your PRIVATE_KEY. Then use this command

 npx hardhat compile

If the compile is successful, folder artifacts and cache will generate in your project the smart contract code.

Now you can copy the code in your backup deploy.js file.

  npx hardhat run scripts/deploy.js --network yournamenetwork

Finally if the compile is successful, your terminal will show your contract address, more information in this video tutorial Deploy SmartContracts.

  • Related