Error: ERROR processing /home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/deploy/01-deploy-fund-me.js:
TypeError: Cannot read properties of undefined (reading '5')
at Object.module.exports [as func] (/home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/deploy/01-deploy-fund-me.js:27:47)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at DeploymentsManager.executeDeployScripts (/home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1219:22)
at DeploymentsManager.runDeploy (/home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
at SimpleTaskDefinition.action (/home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/index.ts:438:5)
at Environment._runTaskDefinition (/home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:308:14)
at Environment.run (/home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:156:14)
at SimpleTaskDefinition.action (/home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/index.ts:584:32)
at Environment._runTaskDefinition (/home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:308:14)
at Environment.run (/home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:156:14)
at DeploymentsManager.executeDeployScripts (/home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at DeploymentsManager.runDeploy (/home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
at SimpleTaskDefinition.action (/home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/index.ts:438:5)
at Environment._runTaskDefinition (/home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:308:14)
at Environment.run (/home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:156:14)
at SimpleTaskDefinition.action (/home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/index.ts:584:32)
at Environment._runTaskDefinition (/home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:308:14)
at Environment.run (/home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:156:14)
at SimpleTaskDefinition.action (/home/surajsahoo/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/index.ts:669:5)
error Command failed with exit code 1.在部署时会出现上述错误。下面提供的js文件01-deploy me.js
const { networkConfig } = require("../helper-hardhat-config")
const { network } = require("hardhat")
const { verify } = require("../utils/verify")
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments
const { deployer } = await getNamedAccounts()
const chainId = network.config.chainId
//const ethUsdPriceFeedAddress = networkConfig[chainId]["ethusdpricefeed"]
let ethUsdPriceFeedAddress
if (chainId == "31337") {
const ethUsdAggregator = await deployments.get("MockV3Aggregator")
ethUsdPriceFeedAddress = ethUsdAggregator.address
} else {
ethUsdPriceFeedAddress = networkConfig[chainId]["ethusdpricefeed"]
}
const fundMe = await deploy("FundMe", {
from: deployer,
args: [ethUsdPriceFeedAddress], //put price feed address
log: true,
waitConfirmations: network.config.blockConfirmations || 1,
})
// if (!developmentChains.includes(network.name)) {
// await verify(fundMe.address, [ethUsdPriceFeedAddress])
// }
}
module.exports.tags = ["all", "fundme"]下面提到的是帮助器-hardhat-config文件。
const networkConfig = {
31337: {
name: "localhost",
},
5: {
name: "goerli",
ethusdpricefeed: "0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e",
},
}
const developmentChain = ["hardhat", "localhost"]
module.export = {
networkConfig,
developmentChain,
}发布于 2023-01-04 08:33:28
看来您正在从这里运行代码https://github.com/PatrickAlphaC/hardhat-fund-me-fcc
我已经检查过了,然后跑了,效果很好。
从错误消息来看,错误发生在deploy/01-deploy-fund-me.js第27行,在您的帖子中甚至缺少行号,但我可以猜到问题代码在ethUsdPriceFeedAddress = networkConfig[chainId]["ethusdpricefeed"],链id是5,根据TypeError: Cannot read properties of undefined (reading '5'),这意味着networkConfig是未定义的。
我注意到,在您的帖子中,有些变量是小写的(比如'ethUsdPriceFeed'),但是在最初的存储库中,它们是camel风格的(比如'ethusdpricefeed')。将您的代码与原始存储库进行比较,以找出差异。
https://ethereum.stackexchange.com/questions/142211
复制相似问题