PatrickAlphaC / hardhat-fund-me-fcc

83 stars 184 forks source link

TypeError: Cannot read properties of undefined (reading 'length') #28

Closed asmar10 closed 2 years ago

asmar10 commented 2 years ago

Hi, im getting this error when i run "yarn hardhat deploy"

this is seems to be in the "00-deploy-mocks.js" file.

TypeError: Cannot read properties of undefined (reading 'length')
    at getFrom (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\helpers.ts:1713:14)  
    at _deploy (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\helpers.ts:533:9)    
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at _deployOne (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\helpers.ts:1004:16)
    at Object.deployFunc [as func] (C:\Users\ROSHAN\hardhat-fundme\deploy\00-deploy-mocks.js:15:9)  
    at DeploymentsManager.executeDeployScripts (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1219:22)
    at DeploymentsManager.runDeploy (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1052:5)
    at SimpleTaskDefinition.action (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\index.ts:438:5)
    at Environment._runTaskDefinition (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat\src\internal\core\runtime-environment.ts:219:14)
    at Environment.run (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat\src\internal\core\runtime-environment.ts:131:14)
    at DeploymentsManager.executeDeployScripts (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1222:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at DeploymentsManager.runDeploy (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1052:5)
    at SimpleTaskDefinition.action (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\index.ts:438:5)
    at Environment._runTaskDefinition (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat\src\internal\core\runtime-environment.ts:219:14)
    at Environment.run (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat\src\internal\core\runtime-environment.ts:131:14)
    at SimpleTaskDefinition.action (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\index.ts:584:32)
    at Environment._runTaskDefinition (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat\src\internal\core\runtime-environment.ts:219:14)
    at Environment.run (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat\src\internal\core\runtime-environment.ts:131:14)
    at SimpleTaskDefinition.action (C:\Users\ROSHAN\hardhat-fundme\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.

Kindly help its been hours!

here's my code:

const { network } = require("hardhat");
const { devChains, _INITIALANSWER, DECIMALS } = require("../hardhat-helper-config.js")

async function deployFunc(hre) {

    hre.getNamedAccounts;
    hre.deployments;

    const { deploy, log } = deployments;
    const { deployer } = await getNamedAccounts();

    if (devChains.includes(network.name)) {
        log("Deploying to development chain..")
        await deploy("MockV3Aggregator", {
            contract: "MockV3Aggregator",
            from: deployer,
            log: true,
            args: [DECIMALS, _INITIALANSWER],
        })
        console.log("Mock deployedd!!")
        console.log("----------------------")

    }
}

module.exports.default = deployFunc;
module.exports.tags = ["all", "mocks"]

PS: i have already added this in my hardhat-config.js file


 NamedAccounts: {
    deployer: {
      default: 0,
    },
  },```
niraj2998 commented 2 years ago

I am not sure about this solution. But instead of this if (devChains.includes(network.name)) can you try this. For this don't for to import network at top const { network } = require("hardhat")

const chainId = network.config.chainId
if (chainId == 31337)
asmar10 commented 2 years ago

still error

krakxn commented 2 years ago

Copy-paste the following code precisely and only replace names of files/paths/variables with what you are using already (as they are my convention):

const { network } = require("hardhat")
const {
    developmentChains,
    DECIMALS,
    INITIAL_ANSWER,
} = require("../helper-hardhat-config")
module.exports = async ({ getNamedAccounts, deployments }) => {
    const { deploy, log } = deployments
    const { deployer } = await getNamedAccounts()
    const chainId = network.config.chainId
    // we need to edploy mocks if we are on a local network
    if (chainId == 31337) {
        log("Local network detected! Deploying mocks...")
        await deploy("MockV3Aggregator", {
            contract: "MockV3Aggregator", // to be really specific
            from: deployer,
            log: true,
            args: [DECIMALS, INITIAL_ANSWER],
        })
        log("Mocks deployed!")
        log("---------------------------------------------------------------")
    }
}

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

Let me know if this helps!

asmar10 commented 2 years ago

Still the same :( i think ill just start from scratch again

krakxn commented 2 years ago

Still the same :( i think ill just start from scratch again

Try this in hardhat config:

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

Still the same :( i think ill just start from scratch again

Try this in hardhat config:

namedAccounts: {
        deployer: {
            default: 0,
        },
        users: {
            default: 0,
        },
    },

THIS WORKED!! THANKS ALOTT

krakxn commented 2 years ago

Still the same :( i think ill just start from scratch again

Try this in hardhat config:

namedAccounts: {
        deployer: {
            default: 0,
        },
        users: {
            default: 0,
        },
    },

THIS WORKED!! THANKS ALOTT

You're welcome! Goodluck with the course!!