1

I'm running through these docs on deploying an NFT and I keep getting the error:

Error HH100: Network ropsten doesn't exist

The command I'm using can be found at step 16:

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


This is what my deploy.js file looks like:

async function main() {
  const MyNFT = await ethers.getContractFactory("MyNFT")

  // Start deployment, returning a promise that resolves to a contract object
  const myNFT = await MyNFT.deploy()
  await myNFT.deployed()
  console.log("Contract deployed to address:", myNFT.address)
}

And this is what my hardhat.config.js file looks like:

/**
* @type import('hardhat/config').HardhatUserConfig
*/
require('dotenv').config();
require("@nomiclabs/hardhat-ethers");
const { API_URL, PRIVATE_KEY } = process.env;
module.exports = {
   solidity: "0.8.1",
   defaultNetwork: "rinkeby",
   networks: {
      hardhat: {},
      rinkeby: {
         url: API_URL,
         accounts: [`0x${PRIVATE_KEY}`]
      }
   },
}

How do I fix this error?

1 Answer 1

3

This hardhat error happens when you are trying to interact with a network that is not defined in the config file.

Specifically, because you are using the --network ropsten flag, the config file expects networks.ropsten to be defined. However, you only have networks.rinkeby defined. I'd recommend adding a definition for networks.ropsten (and making sure to use the appropriate API_URL for ropsten). For example:

/**
* @type import('hardhat/config').HardhatUserConfig
*/
require('dotenv').config();
require("@nomiclabs/hardhat-ethers");
const { RINKEBY_API_URL, ROPSTEN_API_URL, PRIVATE_KEY } = process.env;
module.exports = {
   solidity: "0.8.1",
   defaultNetwork: "rinkeby",
   networks: {
      hardhat: {},
      rinkeby: {
         url: RINKEBY_API_URL,
         accounts: [`0x${PRIVATE_KEY}`]
      },
      ropsten: {
         url: ROPSTEN_API_URL,
         accounts: [`0x${PRIVATE_KEY}`]
      },
   },
}

With this config, if you run:

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

it should work!

P.S. Also make sure you have testnet ether:

2
  • 1
    Had network defined instead of networks! Thanks for the fix :) May 24, 2022 at 8:15
  • those typos can be annoying in hardhat configs :) happy to help! Nov 14, 2022 at 22:35

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.