首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError:无法读取未定义的属性(读取“5”)

TypeError:无法读取未定义的属性(读取“5”)
EN

Ethereum用户
提问于 2023-01-03 06:39:48
回答 1查看 262关注 0票数 0
代码语言:javascript
复制
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

代码语言:javascript
复制
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文件。

代码语言:javascript
复制
const networkConfig = {
    31337: {
        name: "localhost",
    },
    5: {
        name: "goerli",
        ethusdpricefeed: "0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e",
    },
}
const developmentChain = ["hardhat", "localhost"]

module.export = {
    networkConfig,
    developmentChain,
}
EN

回答 1

Ethereum用户

发布于 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')。将您的代码与原始存储库进行比较,以找出差异。

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/142211

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档