PS C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project> npx hardhat deploy --network sepolia
Nothing to compile
An unexpected error occurred:
Error: ERROR processing C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\deploy\01-deploy-fundme.js:
TypeError: Cannot read properties of undefined (reading '11155111')
at Object.module.exports [as func] (C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\deploy\01-deploy-fundme.js:19:47)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at DeploymentsManager.executeDeployScripts (C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1222:22)
at DeploymentsManager.runDeploy (C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1055:5)
at SimpleTaskDefinition.action (C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\node_modules\hardhat-deploy\src\index.ts:438:5)
at Environment._runTaskDefinition (C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\node_modules\hardhat\src\internal\core\runtime-environment.ts:330:14)
at Environment.run (C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\node_modules\hardhat\src\internal\core\runtime-environment.ts:163:14)
at SimpleTaskDefinition.action (C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\node_modules\hardhat-deploy\src\index.ts:584:32)
at Environment._runTaskDefinition (C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\node_modules\hardhat\src\internal\core\runtime-environment.ts:330:14)
at Environment.run (C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\node_modules\hardhat\src\internal\core\runtime-environment.ts:163:14)
at DeploymentsManager.executeDeployScripts (C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1225:19)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at DeploymentsManager.runDeploy (C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1055:5)
at SimpleTaskDefinition.action (C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\node_modules\hardhat-deploy\src\index.ts:438:5)
at Environment._runTaskDefinition (C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\node_modules\hardhat\src\internal\core\runtime-environment.ts:330:14)
at Environment.run (C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\node_modules\hardhat\src\internal\core\runtime-environment.ts:163:14)
at SimpleTaskDefinition.action (C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\node_modules\hardhat-deploy\src\index.ts:584:32)
at Environment._runTaskDefinition (C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\node_modules\hardhat\src\internal\core\runtime-environment.ts:330:14)
at Environment.run (C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\node_modules\hardhat\src\internal\core\runtime-environment.ts:163:14)
at SimpleTaskDefinition.action (C:\Users\BISHOP\Desktop\blockchain_fcc\hardhat-fundme-project\node_modules\hardhat-deploy\src\index.ts:669:5)在部署到sepolia测试网时,会出现上述错误。下面提供的是文件01-deploy-fundme.js
//imports
const { network } = require("hardhat")
const { networkConfig } = require("../helper-hardhat-config")
const { verify } = require("../utils/verify")
require("dotenv").config()
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments
const { deployer } = await getNamedAccounts()
const chainId = network.config.chainId
let ethUsdPriceFeedAddress
//Should use a mock when going for localhost network or hardhat
if (chainId === 31337) {
const ethUsdAggregator = await deployments.get("MockV3Aggregator")
ethUsdPriceFeedAddress = ethUsdAggregator.address
} else {
ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"]
}
const args = [ethUsdPriceFeedAddress]
log("Deploying Fundme contract and waiting for confirmations...")
const fundMe = await deploy("FundMe", {
from: deployer,
args: args, //The Price Feed Address is to enter the constructor in the contract.
log: true,
waitConfirmations: network.config.blockConfirmations || 1,
})
log(`Fudme contracts deployed at: ${fundMe.address}`)
log("___________________________________________")
// await verify(fundMe.address, args)
if (!chainId == 31337 && process.env.ETHERSCAN_API_KEY) {
await verify(fundMe.address, args)
}
}
module.exports.tabs = ["all", "fundme"]下面是helper-hardhat-config.js
const networkConfig = {
31337: {
name: "localhost"
},
11155111: {
name: "sepolia",
ethUsdPriceFeed: "0x694AA1769357215DE4FAC081bf1f309aDC325306",
},
// 137: {
// name: "mumbai", //Polygon Testnet
// ethUsdPriceFeed: "0x0715A7794a1dc8e42615F059dD6e406A6594651A",
// },
}
const developmentChains = ["hardhat", "localhost"]
module.export = {
networkConfig,
developmentChains,
}下面是hardhat-config.js
require("@nomicfoundation/hardhat-toolbox")
require("dotenv").config()
require("@nomiclabs/hardhat-etherscan")
require("hardhat-gas-reporter")
require("solidity-coverage")
require("hardhat-deploy")
require("@nomiclabs/hardhat-ethers")
/** @type import('hardhat/config').HardhatUserConfig */
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL
const PRIVATE_KEY = process.env.PRIVATE_KEY
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY || ""
const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY
module.exports = {
solidity: {
compilers: [{ version: "0.8.18" }, { version: "0.6.6" }],
},
defaultNetwork: "hardhat",
networks: {
sepolia: {
url: SEPOLIA_RPC_URL,
accounts: [PRIVATE_KEY],
chainId: 11155111,
blockConfirmations: 6,
},
localhost: {
url: "http://127.0.0.1:8545/",
chainId: 31337,
},
},
etherscan: {
apiKey: {
sepolia: ETHERSCAN_API_KEY,
},
},
gasReporter: {
enabled: false,
outputFile: "gas-report.txt",
noColors: true,
currency: "USD",
coinmarketcap: COINMARKETCAP_API_KEY,
token: "MATIC",
},
namedAccounts: {
deployer: {
default: 0, // here this will by default take the first account as deployer
1: 0, // similarly on mainnet it will take the first account as deployer. Note though that depending on how hardhat network are configured, the account 0 on one network can be different than on another
},
},
}有人能帮帮我吗。谢谢
发布于 2023-05-01 11:09:58
我找到了解决方案,会弹出错误,因为在01- deploy -fundme.js文件中,您从帮助文件访问networkConfig,帮助文件试图读取11155111的网络设置,但是部署文件中没有定义networkConfig变量。
原因是,在您的助手文件中,您没有正确地导出变量;
module.export = {
networkConfig,
developmentChains,
}应该是module.exports而不是module.export;
module.exports = {
networkConfig,
developmentChains,
}https://ethereum.stackexchange.com/questions/149675
复制相似问题