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

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

Ethereum用户
提问于 2023-04-30 16:26:21
回答 1查看 18关注 0票数 0
代码语言:javascript
复制
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

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

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

代码语言:javascript
复制
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
        },
    },
}

有人能帮帮我吗。谢谢

EN

回答 1

Ethereum用户

发布于 2023-05-01 11:09:58

我找到了解决方案,会弹出错误,因为在01- deploy -fundme.js文件中,您从帮助文件访问networkConfig,帮助文件试图读取11155111的网络设置,但是部署文件中没有定义networkConfig变量。

原因是,在您的助手文件中,您没有正确地导出变量;

代码语言:javascript
复制
module.export = {
    networkConfig,
    developmentChains,
}

应该是module.exports而不是module.export;

代码语言:javascript
复制
module.exports = {
    networkConfig,
    developmentChains,
}
票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

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

复制
相关文章

相似问题

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