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

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

Ethereum用户
提问于 2022-10-17 10:12:28
回答 1查看 198关注 0票数 0

下面是我部署模拟合同的代码:

代码语言:javascript
复制
const { network, ethers } = require("hardhat")
const { developmentChains } = require("../helper-hardhat-config")

const BASE_FEE = "250000000000000000" //ethers.utils.parseEther("0.25") 
const GAS_PRICE_LINK = 1e9 // 1000000000

module.exports = async function ({ getNamedAccounts, deployments }) {
    const { deploy, log } = deployments
    const { deployer } = getNamedAccounts()
    const chainId = network.config.chainId
    // const args = [BASE_FEE, GAS_PRICE_LINK]

    if (chainId == 31337) {
        log("Local network detected! Deploying Mock...")
    }
 
    await deploy("VRFCoordinatorV2Mock", {
        from: deployer,
        log: true,
        args: [BASE_FEE, GAS_PRICE_LINK],
    })
    log("MOCK DEPOYED......!")
    log("------------------------------------")
}

module.exports.tags = ["all", "mocks"]

这是一个错误:

代码语言:javascript
复制
   Error: ERROR processing /home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/deploy/00-deploy-mocks.js:
    TypeError: Cannot read properties of undefined (reading 'length')
        at getFrom (/home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/node_modules/hardhat-deploy/src/helpers.ts:1713:14)
        at _deploy (/home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/node_modules/hardhat-deploy/src/helpers.ts:533:9)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at _deployOne (/home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/node_modules/hardhat-deploy/src/helpers.ts:1004:16)
        at Object.module.exports [as func] (/home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/deploy/00-deploy-mocks.js:17:5)
        at DeploymentsManager.executeDeployScripts (/home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1219:22)
        at DeploymentsManager.runDeploy (/home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
        at SimpleTaskDefinition.action (/home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/node_modules/hardhat-deploy/src/index.ts:438:5)
        at Environment._runTaskDefinition (/home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:308:14)
        at Environment.run (/home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:156:14)
        at DeploymentsManager.executeDeployScripts (/home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at DeploymentsManager.runDeploy (/home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
        at SimpleTaskDefinition.action (/home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/node_modules/hardhat-deploy/src/index.ts:438:5)
        at Environment._runTaskDefinition (/home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:308:14)
        at Environment.run (/home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:156:14)
        at SimpleTaskDefinition.action (/home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/node_modules/hardhat-deploy/src/index.ts:584:32)
        at Environment._runTaskDefinition (/home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:308:14)
        at Environment.run (/home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:156:14)
        at SimpleTaskDefinition.action (/home/arpit/hh-fcc/hardhat-smartcontract-lottery-fcc/node_modules/hardhat-deploy/src/index.ts:669:5)
    error Command failed with exit code 1.

有人能告诉我我的密码出了什么问题吗?

这个项目的GitHub回购:https://github.com/Arpit7707/hardhat-raffle-fcc

EN

回答 1

Ethereum用户

发布于 2023-01-17 05:32:37

我遵循同样的教程,也有同样的问题。

您可以通过在await之前添加getNamedAccounts()来解决这个问题,因为它是一个异步函数。

这将允许getNamedAccounts()函数在继续执行下一行代码之前完成执行。

改变这一点:

代码语言:javascript
复制
 const { deployer } = getNamedAccounts()

代码语言:javascript
复制
 const { deployer } = await getNamedAccounts()

希望能帮上忙!

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

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

复制
相关文章

相似问题

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