【问题标题】:Hardhat Config Error HH100: Network goerli doesn't exist安全帽配置错误 HH100:网络 goerli 不存在
【发布时间】:2022-07-13 02:33:00
【问题描述】:

我正在尝试在 Goerli 上部署合约,但我不断收到错误 Error HH100: Network goerli doesn't exist

这是我的hardhat.config.ts

require("dotenv").config();
import { task } from 'hardhat/config';
import '@nomiclabs/hardhat-waffle';
import '@typechain/hardhat'
import '@nomiclabs/hardhat-ethers';
import { HardhatUserConfig } from "hardhat/config";


const PrivateKey = "b427...";

const config: HardhatUserConfig = {
  solidity: {
        version: '0.8.0',
        },
  networks: {
        goerli: {
                chainId: 5,
                url: "https://goerli.infura.io/v3/309820d3955640ec9cda472d998479ef",
                accounts: [PrivateKey],
        },
  },
 };

// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task('accounts', 'Prints the list of accounts', async (taskArgs, hre) => {
  const accounts = await hre.ethers.getSigners();

  for (const account of accounts) {
    console.log(account.address);
  }
});

// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
export default {
  solidity: '0.8.0',
};

谢谢!

我不知道我应该添加什么,但请询问,我会发布更多信息。

【问题讨论】:

  • 你试过答案了吗?
  • 您尝试部署到 Goerli 时运行的命令是什么?
  • 在我的例子中,我已将 defaultNetwork 设置为 goerli,但没有更新网络部分以包含它(它被预设为 ropsten)。

标签: typescript config ethereum hardhat


【解决方案1】:

我在两天前遇到了这个错误。我可以通过这一步解决它。

  1. 将项目文件夹中的所有文件和文件夹备份到。
  2. 删除项目文件夹中的所有文件和文件夹并重写npm命令。

npm 初始化

  1. 在您的文件夹中生成 package.json 文件。

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

  1. 选择。

创建一个空的 hardhat.config.js

现在您的项目是安装安全帽。并创建将备份文件夹中的所有文件夹和可靠代码复制到您的项目文件夹但是如果您有工件和缓存文件夹,请不要复制它。

并在 hardhar.config.js 文件中将此代码粘贴到顶部。

require('@nomiclabs/hardhat-ethers')
const API_URL = "Your testnet rpc link";
const PRIVATE_KEY = "Your Private Accout address"
const PUBLIC_KEY = "Your Account Address";

并在module.module中导出代码。

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

检查 0x${} 确保它在您的 PRIVATE_KEY 中。然后使用这个命令

npx 安全帽编译

如果编译成功,文件夹工件和缓存将在您的项目中生成并生成智能合约代码。并在备份的 deploy.js 文件中复制代码。

现在使用此命令部署.js 文件

npx 安全帽运行脚本/deploy.js --network yournamenetwork

如果编译成功,你的终端会显示你的合约地址

您可以在此处查看此视频教程。

Deploy Smart Contract.

或我的 git Repo smart_contract 文件夹,例如

Git Repo.

【讨论】:

    【解决方案2】:
     [`0x${PrivateKey}`]
    

    检查 0x${} 确保它在您的 PRIVATE_KEY 中

    【讨论】:

      猜你喜欢
      • 2022-07-13
      • 1970-01-01
      • 1970-01-01
      • 2017-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多