0

I am having issues deploying my smart contract in hardhat using the sepolia test net. I keep getting the "Network sepolia doesnt exist" error as well as "Option moduleresolution must be set next to NodeNext" error when I switch over to typescript( I would rather use javaScript). Here is my configuration file with my deploy script below it. Please help as I am very frustrated as to what is going wrong( This is my first project so I am anxious haha).

require("@nomicfoundation/hardhat-toolbox");

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

           const { API_URL, PRIVATE_KEY } = process.env;
           require("dotenv").config();
           require("@nomicfoundation/hardhat-ethers");
           import("@nomicfoundation/hardhat-chai-matchers");
           import("@nomicfoundation/hardhat-ethers");

           module.exports = {
              solidity: {
               compilers: [
               {
             version: "0.5.9",
             },
            {
             version: "0.8.0",
            },
           {
          version: "0.8.19",
           },
          {
          version: "0.8.9",
          },
          {
          version: "0.8.21",
          },
          ],

           defaultNetwork: "sepolia",
             networks: {
             hardhat: {},
             sepolia: {
                 url: API_URL,
                 accounts: ["0x${PRIVATE_KEY}"],
                 chainId: 11155111,
                },
               },
              },
            };

my deploy script named SpiderVerseDeploy.js

           import { ethers } from "hardhat";
           import "hardhat/console.sol";

           async function main() {
             const SpiderVerse = await ethers.getContractFactory("SpiderVerse");
             const spiderVerse = await SpiderVerse.deploy("SpiderVerse");

             await spiderVerse.deployed();

              console.log("Contract deployed to address:", spiderVerse.address);
             }

              main();
              main().catch((error) => {
              console.error(error);
              process.exitCode = 1;
            });



  

I have my private information stored as variables in a .env file and set up my sepolia testnet account in my metamask wallet.

2 Answers 2

0

Couple of basic things I would say to try:

  1. accounts : [PRIVATE_KEY] instead of accounts: ["0x${PRIVATE_KEY}"].
  2. Remove chainId, it's not needed.
  3. make sure you are running the command right. i.e.

npx hardhat run ./scripts/SpiderVerseDeploy.js --network sepolia

2
  • hello. thank you for responding. It is still telling me that the sepolia network doesnt exist. i really have no clue as to why its doing this. I believe I have all the packages installed so idk. It is very annoying.
    – EGstacking
    Sep 4, 2023 at 14:04
  • This is strange, do you have a github repo for the same project, I can try on my machine and check what's the issue. Sep 4, 2023 at 16:24
0

Basically, Hardhat recently made the little few changes in the deployment script. You have to change them in your code let me show you

update the hardhat.config.js file

require("@nomicfoundation/hardhat-toolbox");

require("@nomicfoundation/hardhat-verify");

require('dotenv').config();

const {PRIVATE_KEY, URL, APIKEY } = process.env;

  module.exports = {
     solidity: "0.8.19",
     defaultNetwork: "sepolia",
     networks: {
        hardhat: {},
      
       sepolia: {
          url: URL,                          //Infura/Alchemy RPC-URL for sepolia
          accounts: [`0x${PRIVATE_KEY}`],    //Metamask Private Key
        },

     },

     etherscan: {
      apiKey: APIKEY,
    },
  }

Update the deploy.js File

const hre = require("hardhat");

async function main() {

  const lock = await hre.ethers.deployContract("Lock");

  await lock.waitForDeployment();

  console.log(`contract is deployed to ${lock.target}`);
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});
2
  • Ok I see. I will give it a shot. Also when I store my information for my private key how would I store it in the process.env file? What would be the syntax is what I mean? As in would I have to put [0x${PRIVATE_KEY}] before my key?
    – EGstacking
    Sep 7, 2023 at 14:40
  • in the .env file just copy the private key from your wallet and paste it as it is
    – Afaq Ahsan
    Sep 12, 2023 at 8:57

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.