0

I have an issue with deploying smart contract on Goerli network. When I trying to run the contract I get Error

Error HH100: Network goerli doesn't exist

Here is example of my code

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract FICEToken is ERC20 {
    constructor() ERC20("Token", "TKN") {
        _mint(msg.sender, 10000 * 10 ** decimals());
    }
}

deploy.js

const hre = require("hardhat");

async function main() {
  const currentTimestampInSeconds = Math.round(Date.now() / 1000);
  const unlockTime = currentTimestampInSeconds + 60;

  const lockedAmount = hre.ethers.parseEther("0.001");

  const lock = await hre.ethers.deployContract("Token", [unlockTime], {
    value: lockedAmount,
  });

  await lock.waitForDeployment();

  console.log(
    `Lock with ${ethers.formatEther(
      lockedAmount
    )}ETH and unlock timestamp ${unlockTime} 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;
});

hardhat.config.js

require('@nomiclabs/hardhat-waffle')

const PRIVATE_KEY = 'PRIVATE KEY'
const GOERLI_RPC_URL = 'https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161'

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  defaultNetwork: "goerli",
  networks: {
    hardhat: {},
    goerli: {
      url: GOERLI_RPC_URL,
      accounts:[`0x${PRIVATE_KEY}`],
      chainID: 5,
    }
  },
  solidity: "0.8.19",
  };

What can I do to solve this problem?

1
  • what is the command you are using to run deploy.js ?
    – Nikhil
    Oct 31, 2023 at 9:14

1 Answer 1

0

I'm a Developer Advocate at Chainstack.

Based on your query, there are a couple of issues to address:

  1. The deploy script you're using appears to be the default sample from Hardhat, not tailored for your specific smart contract.
  2. You seem to be using an outdated version of Hardhat.

Let's resolve these step-by-step:

Update Hardhat

First, update to the latest version of Hardhat. Follow the official documentation for guidance.

Initialize a New Project

Create a new Hardhat project. During initialization, opt to install hardhat-toolbox.

Install Dependencies

Ensure you've installed OpenZeppelin contracts:

npm install @openzeppelin/contracts

Smart contract

The smart contract you posted is ok.

Configure Hardhat

Add your private keys and RPC to the following.

I strongly recommend using dotevn to get the sensitive info from a .env file.

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

const PRIVATE_KEY = "PRIVATE_KEY";
const GOERLI_RPC_URL = "YOUR_RPC_URL";

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  defaultNetwork: "goerli",
  networks: {
    goerli: {
      url: GOERLI_RPC_URL,
      accounts: [PRIVATE_KEY],
    },
  },
  solidity: "0.8.20",
};

For more on using .env files, refer to this guide.

Deploy Script

Here's a sample deploy.js:

const hre = require("hardhat");

async function main() {
  console.log("Deploying contract...");

  // Deploy the contract
  const FICEToken = await hre.ethers.deployContract("FICEToken");

  // Wait for the transaction to be mined
  await FICEToken.waitForDeployment();

  // Log the address of the deployed contract
  console.log("Contract deployed to:", FICEToken.target);
}

// Execute the script and handle errors
main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

Remember that this will only work with the same smart contract you have in your post (because of the name).

If you change the name of the contract, edit it in this line:

hre.ethers.deployContract("FICEToken");

Compilation and Deployment

Compile your smart contract:

npx hardhat compile

Deploy it:

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

It will return a result like this:

Deploying contract...
Contract deployed to: 0xa804D8845263719e2E9bff14930cE738950FB623

Additional Note

For testing, consider using the Sepolia network as it's recommended for smart contracts and DApps. Just FIY :)

Feel free to reach out if you need more help!

1
  • 1
    Thank you so much) Now everything works fine)
    – Victor
    Nov 2, 2023 at 17:55

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.