0

Here's my code for deploying a mock contract :

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"]

And Here's the error:

   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.

Can anyone tell me what's wrong with my code?

GitHub repo for this project: [https://github.com/Arpit7707/hardhat-raffle-fcc]

1 Answer 1

1

I'm following the same tutorial and had the same issue.

You can solve the problem by adding await before the getNamedAccounts() because it's an async function.

This will allow the getNamedAccounts() function to finish executing before proceeding to the next line of code.

Change this:

 const { deployer } = getNamedAccounts()

to

 const { deployer } = await getNamedAccounts()

Hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.