Solidity

安全帽配置問題的錯誤部署

  • March 22, 2022

我的配置文件中有錯誤:錯誤 HH8:您的配置文件中有一個或多個錯誤:

 * Invalid value undefined for HardhatConfig.networks.rinkeby.url - Expected a value of type string.
 * Invalid value {} for HardhatConfig.networks.rinkeby - Expected a value of type HttpNetworkHDAccountsConfig.
 * Invalid value undefined for HardhatConfig.networks.ropsten.url - Expected a value of type string.
 * Invalid value {} for HardhatConfig.networks.ropsten - Expected a value of type HttpNetworkHDAccountsConfig.
 * Invalid value {} for HardhatConfig.networks.ganache - Expected a value of type HttpNetworkHDAccountsConfig.
 * Invalid value undefined for HardhatConfig.networks.mainnet.url - Expected a value of type string.
 * Invalid value {} for HardhatConfig.networks.mainnet - Expected a value of type HttpNetworkHDAccountsConfig.
 * Invalid value {} for HardhatConfig.networks.polygon - Expected a value of type HttpNetworkHDAccountsConfig.
 
To learn more about Hardhat's configuration, please go to https://hardhat.org/config/

我的配置文件:

require("@nomiclabs/hardhat-waffle");
require("@nomiclabs/hardhat-etherscan");


require('dotenv').config()

// 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);
 }
});
const MAINNET_RPC_URL = process.env.MAINNET_RPC_URL || process.env.ALCHEMY_MAINNET_RPC_URL
const RINKEBY_RPC_URL = process.env.RINKEBY_RPC_URL
const ROPSTEN_RPC_URL = process.env.ROPSTEN_RPC_URL
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY
const MNEMONIC = process.env.MNEMONIC
module.exports = {
 solidity: "0.8.4",
 networks: {
  

   rinkeby: {
     url: RINKEBY_RPC_URL,
     // accounts: [PRIVATE_KEY],
     accounts: {
       mnemonic: MNEMONIC,
     },
     saveDeployments: true,
   },
   ropsten: {
     url: ROPSTEN_RPC_URL,
     // accounts: [PRIVATE_KEY],
     accounts: {
       mnemonic: MNEMONIC,
     },
     saveDeployments: true,
   },
   ganache: {
     url: 'http://localhost:8545',
     accounts: {
       mnemonic: MNEMONIC,
     }
   },
   mainnet: {
     url: MAINNET_RPC_URL,
     // accounts: [PRIVATE_KEY],
     accounts: {
       mnemonic: MNEMONIC,
     },
     saveDeployments: true,
   },
   polygon: {
     url: "https://rpc-mainnet.maticvigil.com/",
     // accounts: [PRIVATE_KEY],
     accounts: {
       mnemonic: MNEMONIC,
     },
     saveDeployments: true,

   }
 },
 etherscan: {
   // Your API key for Etherscan
   // Obtain one at https://etherscan.io/
   apiKey: ETHERSCAN_API_KEY
 },
 mocha: {
   timeout: 100000
 }
};

我實際上使用上面的配置文件將智能合約部署到不同的網路幾次。知道我不知道發生了什麼變化。有任何想法嗎?

您使用的似乎是一個env變數,因此要麼添加前綴process.env(如果這些變數在 .env 中定義),要麼硬編碼“HTTP”地址

林克比的一個例子:

rinkeby: {
     url: process.env.RINKEBY_RPC_URL || "http://your-rinkeby-provider",
     accounts: {
       mnemonic: MNEMONIC,
     },
   },

你的 .env 應該是這樣的:

  ETHERSCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1
  RINKEBY_RPC_URL=https://eth-rinkeby.alchemyapi.io/
  PRIVATE_KEY=0xabc123abc123abc123abc123abc123abc123abc123abc...

process.env要訪問這些變數,您需要process.env.RINKEBY_RPC_URL在您的hardhat-config

找到了我的問題的根源。我使用 .gitignore 文件來自 github 上的 pre-build .gitignore 文件夾-節點一(可以在這裡看到)可能忽略了我需要的東西(不知道具體是什麼)。

引用自:https://ethereum.stackexchange.com/questions/124342