PatrickAlphaC / hardhat-fund-me-fcc

83 stars 184 forks source link

TypeError: Cannot read properties of undefined (reading 'ethUsdPriceFeed') #7

Closed celalaksu closed 2 years ago

celalaksu commented 2 years ago

yarn hardhat deploy --network rinkeby deploy error

 yarn run v1.22.15
warning package.json: No license field
$ /home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/.bin/hardhat deploy --network rinkeby
Nothing to compile
An unexpected error occurred:

Error: ERROR processing /home/eemcs/freecodecamp/hardhat-fund-me-cc/deploy/01-deploy-fund-me.js:
TypeError: Cannot read properties of undefined (reading 'ethUsdPriceFeed')
    at Object.module.exports.default [as func] (/home/eemcs/freecodecamp/hardhat-fund-me-cc/deploy/01-deploy-fund-me.js:17:56)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at DeploymentsManager.executeDeployScripts (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1219:22)
    at DeploymentsManager.runDeploy (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
    at SimpleTaskDefinition.action (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/index.ts:438:5)
    at Environment._runTaskDefinition (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at Environment.run (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at SimpleTaskDefinition.action (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/index.ts:584:32)
    at Environment._runTaskDefinition (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at Environment.run (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at DeploymentsManager.executeDeployScripts (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at DeploymentsManager.runDeploy (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
    at SimpleTaskDefinition.action (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/index.ts:438:5)
    at Environment._runTaskDefinition (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at Environment.run (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at SimpleTaskDefinition.action (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/index.ts:584:32)
    at Environment._runTaskDefinition (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at Environment.run (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at SimpleTaskDefinition.action (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/index.ts:669:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

01-deploy-fund-me.js

const { getNamedAccounts, deployments, network } = require("hardhat")
const { networkConfig, developmentChains } = require("../helper-hardhat-config")
const { verify } = require("../utils/verify")

module.exports.default = async ({ getNamedAccounts, deployments }) => {
    const { deploy, log } = deployments
    const { deployer } = await getNamedAccounts()
    const chainId = network.config.chainId

    //const addres = "0x8A753747A1Fa494EC906cE90E9f37563A8AF630e"

    let ethUsdPriceFeedAddress
    if (developmentChains.includes(network.name)) {
        const ethUsdAggregator = await deployments.get("MockV3Aggregator")
        ethUsdPriceFeedAddress = ethUsdAggregator.address
    } else {
        ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"]
    }

    const args = [ethUsdPriceFeedAddress]
    const fundMe = await deploy("FundMe", {
        from: deployer,
        args: args,
        log: true,
        waitConfirmation: network.config.blockConfirmations || 1,
    })

    if (
        !developmentChains.includes(network.name) &&
        process.env.ETHERSCAN_API_KEY
    ) {
        await verify(fundMe.address, args)
    }
    log("________________________________________________________")
}

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

helper-hardhat-config.js

const networkConfig = {
    4: {
        name: "rinkeby",
        ethUsdPriceFeed: "0x8A753747A1Fa494EC906cE90E9f37563A8AF630e",
    },
    137: {
        name: "polygon",
        ethUsdPriceFeed: "0xF9680D99D6C9589e2a93a78A04A279e509205945",
    },
}
const developmentChains = ["hardhat", "localhost"]
const DECIMALS = 8
const INITAL_ANSWER = 200000000000

module.exports = {
    networkConfig,
    developmentChains,
    DECIMALS,
    INITAL_ANSWER,
}
FerraroSoftware commented 2 years ago

Try updating your network.name !developmentChains.includes(network.naem) && to !developmentChains.includes(network.name) &&

celalaksu commented 2 years ago

Thank you @FerraroSoftware . I fixed it but the same error persists.

When i use address directly ethUsdPriceFeedAddress = "0x8A753747A1Fa494EC906cE90E9f37563A8AF630e" instead of ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"] It gives this error

Error: ERROR processing /home/eemcs/freecodecamp/hardhat-fund-me-cc/deploy/01-deploy-fund-me.js:
TypeError: Cannot read properties of undefined (reading 'length')
    at getFrom (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/helpers.ts:1713:14)
    at _deploy (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/helpers.ts:533:9)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at _deployOne (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/helpers.ts:1004:16)
    at Object.module.exports.default [as func] (/home/eemcs/freecodecamp/hardhat-fund-me-cc/deploy/01-deploy-fund-me.js:22:20)
    at DeploymentsManager.executeDeployScripts (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1219:22)
    at DeploymentsManager.runDeploy (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
    at SimpleTaskDefinition.action (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/index.ts:438:5)
    at Environment._runTaskDefinition (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at Environment.run (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at DeploymentsManager.executeDeployScripts (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at DeploymentsManager.runDeploy (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
    at SimpleTaskDefinition.action (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/index.ts:438:5)
    at Environment._runTaskDefinition (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at Environment.run (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at SimpleTaskDefinition.action (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/index.ts:584:32)
    at Environment._runTaskDefinition (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at Environment.run (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at SimpleTaskDefinition.action (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/index.ts:669:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
rodriguesnavil commented 2 years ago

@celalaksu In 01-deploy-fund-me.js file, Can you console chainId and tell me what output you are getting?

celalaksu commented 2 years ago

Thank you @rodriguesnavil. There was an syntax mistake about chainId. I fixed it . But i have same error TypeError: Cannot read properties of undefined (reading 'length') Chain Id is 4. I tried orj repo and i get same error. Is there any installation I forget? I added RINKEBY_RPC_URL, PRIVATE_KEY from metamask rinkeby testnet ( and added to .env file without "0x" ), ETHERSCAN_API_KEY, COINMARKETCAP_API_KEY to .env file.

require("dotenv").config()
require("@nomiclabs/hardhat-etherscan")
require("@nomiclabs/hardhat-waffle")
require("hardhat-gas-reporter")
require("solidity-coverage")
require("hardhat-deploy")

/**
 * @type import('hardhat/config').HardhatUserConfig
 */
const RINKEBY_RPC_URL = process.env.RINKEBY_RPC_URL
const PRIVATE_KEY = process.env.PRIVATE_KEY
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY
const COINMARKEKETCAP_API_KEY = process.env.COINMARKEKETCAP_API_KEY

module.exports = {
    //solidity: "0.8.8",
    solidity: {
        compilers: [{ version: "0.8.8" }, { version: "0.6.6" }],
    },
    defaultNetwork: "hardhat",
    networks: {
        rinkeby: {
            url: RINKEBY_RPC_URL,
            accounts: [PRIVATE_KEY],
            chainId: 4,
            blockConfirmations: 6,
        },
    },
    gasReporter: {
        enabled: true,
        outputFile: "gas-report.txt",
        noColors: true,
        currency: "USD",
        coinmarketcap: COINMARKEKETCAP_API_KEY,
        token: "MATIC",
    },
    etherscan: {
        apiKey: ETHERSCAN_API_KEY,
    },
    namedAccounts: {
        deployer: {
            default: 0,
            1: 0,
            4: 1,
        },
    },
}
PatrickAlphaC commented 2 years ago

Update the namedaccounts section:

    namedAccounts: {
        deployer: {
            default: 0,
        },
    },
celalaksu commented 2 years ago

Thank you @PatrickAlphaC. It worked

sadityakumar9211 commented 2 years ago

I faced the same issue and this solution worked for me too. But I am a little confused, why did this happen in the first place? Why adding chainId: index key-value pair in the deployer was creating this error? Would someone please explain this?