PatrickAlphaC / hardhat-fund-me-fcc

82 stars 183 forks source link

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

Closed shawnesquivel closed 1 year ago

shawnesquivel commented 1 year ago

when trying to deploy the 00-mocks-.js script, I get the following error:

Error: ERROR processing /home/shawnesquivel/hh-fcc/hardhat-fund-me-fcc/deploy/00-deploy-mocks.js:
TypeError: Cannot read properties of undefined (reading 'length')
    at getFrom (/home/shawnesquivel/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/helpers.ts:1727:14)
    at _deploy (/home/shawnesquivel/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/helpers.ts:534:9)

From my understanding, when grab the deployer from getNamedAccounts, it will use the namedAccounts in the hardhat.config.js. So I made sure that the deployer had a default of 0.

00-deploy-mocks.js

if I add

log(deployer)

it shows that deployer is undefined, so there must be an issue with getNamedAccounts which gets the namedAccounts from hardhat.config.js

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

    if (chainId == 31337) {
        await deploy("MockV3Aggregator", {
            contract: "MockV3Aggregator",
            from: deployer,
            log: true,
            args: [DECIMALS, INITIAL_ANSWER],
        })
    }
}

hardhat.config.js - made sure namedAccounts.deployer had a default of 0

module.exports = {
    defaultNetwork: "hardhat",
 ... 
   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
        },
    },
}

package.json - same as in GitHub repo https://github.com/PatrickAlphaC/hardhat-fund-me-fcc/blob/main/package.json

shawnesquivel commented 1 year ago

I tried referencing this solution:

https://github.com/PatrickAlphaC/hardhat-fund-me-fcc/issues/28

by using this in hardhat.config.js, but unfortunately I'm getting the same error.

module.exports = {
...
    namedAccounts: {
        deployer: {
            default: 0,
        },
        users: {
            default: 0,
        },
    },
}
shawnesquivel commented 1 year ago

Fixed. Since {deployer} was undefined, I looked up how getNamedAccounts is working. Simple syntax error!

    const { deployer } = await getNamedAccounts

returns an AsyncFunction. Odd. Wait - I'm not even calling the function!! Changed to this:

    const { deployer } = await getNamedAccounts()