PatrickAlphaC / dao-template

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

ChinmayGopal931 opened this issue · comments

Hi @PatrickAlphaC @zeuslawyer ,
I am following your tutorial step by step instead of cloning the the repo and I am running into this error when I try to deploy:

yarn hardhat deploy --show-stack-traces
yarn run v1.22.19
warning package.json: No license field
$ /home/chinmay/dev/governance/node_modules/.bin/hardhat deploy --show-stack-traces
Nothing to compile
No need to generate any newer typings.
----------------------------------------------------
Deploying GovernanceToken and waiting for confirmations...
An unexpected error occurred:

Error: ERROR processing /home/chinmay/dev/governance/deploy/deploy-Governance-token.ts:
TypeError: Cannot read properties of undefined (reading 'length')
 at getFrom (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/helpers.ts:1713:14)
 at _deploy (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/helpers.ts:533:9)
 at processTicksAndRejections (node:internal/process/task_queues:96:5)
 at async _deployOne (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/helpers.ts:1004:16)
 at async Object.deployGovernanceToken [as func] (/home/chinmay/dev/governance/deploy/deploy-Governance-token.ts:14:27)
 at async DeploymentsManager.executeDeployScripts (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1219:22)
 at async DeploymentsManager.runDeploy (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
 at async SimpleTaskDefinition.action (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/index.ts:438:5)
 at async Environment._runTaskDefinition (/home/chinmay/dev/governance/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
 at async Environment.run (/home/chinmay/dev/governance/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
 at DeploymentsManager.executeDeployScripts (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19)
 at processTicksAndRejections (node:internal/process/task_queues:96:5)
 at async DeploymentsManager.runDeploy (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
 at async SimpleTaskDefinition.action (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/index.ts:438:5)
 at async Environment._runTaskDefinition (/home/chinmay/dev/governance/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
 at async Environment.run (/home/chinmay/dev/governance/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
 at async SimpleTaskDefinition.action (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/index.ts:584:32)
 at async Environment._runTaskDefinition (/home/chinmay/dev/governance/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
 at async Environment.run (/home/chinmay/dev/governance/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
 at async SimpleTaskDefinition.action (/home/chinmay/dev/governance/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.

Really not sure what to do but it does seem very similar to another issue created here: PatrickAlphaC/all-on-chain-generated-nft#6

commented

hi @ChinmayGopal931
Yeah sometimes those errors arent very helpful -- this one doesnt tell us which line in deploy-Governance-token.ts is throwing this error, so it's hard to tell what is undefined.

One way to troubleshoot this is to add console.logs every couple of lines to see roughly where it fails. And look carefully at what is being run just before the failure and after the previous console log. That narrows it down to the problematic lines.

Since the stack trace isnt point to deploy-Governance-token.ts specifically, I'm thinking it has something to do with your config. But narrowing down the lines should help. A common error is not awaiting on async code, and then the variable you're reading from is actually undefined etc.

@zeuslawyer ,
The error is caused by this line : const governanceToken = await deploy("GovernanceToken", { from: deployer, args: [], log: true, });

Also here is my config file:

/**
 * @type import('hardhat/config').HardhatUserConfig
 */
 import "@typechain/hardhat"
 import "@nomiclabs/hardhat-waffle"
 import "@nomiclabs/hardhat-etherscan"
 import "@nomiclabs/hardhat-ethers"
 import "dotenv/config"
 import "solidity-coverage"
 import "hardhat-deploy"
 import { HardhatUserConfig } from "hardhat/config"

module.exports = {
  solidity: "0.8.4",
};
const RINKEBY_RPC_URL ="i have used a proper url"
const PRIVATE_KEY = "this is a proper private key"

const config: HardhatUserConfig={
  defaultNetwork: "hardhat",
  networks: {
    hardhat: {
      chainId: 31337,
    },
    localhost: {
      chainId: 31337,
    },
    rinkeby: {
      url: RINKEBY_RPC_URL,
      accounts: [PRIVATE_KEY],
      chainId: 4,
    },
  }
}
export default config;

Also here is the contract for refrence:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";

contract GovernanceToken is ERC20, ERC20Permit, ERC20Votes {
    constructor() ERC20("GovernanceToken", "GT") ERC20Permit("GovernanceToken") {}

    // The functions below are overrides required by Solidity.

    function _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal override(ERC20, ERC20Votes) {
        super._afterTokenTransfer(from, to, amount);
    }

    function _mint(address to, uint256 amount) internal override(ERC20, ERC20Votes) {
        super._mint(to, amount);
    }

    function _burn(address account, uint256 amount) internal override(ERC20, ERC20Votes) {
        super._burn(account, amount);
    }
}

ALchemy seems to be depriciating rinkeby . Could that be it?

Also the error I get when I run yarn hardhat node

yarn hardhat node --show-stack-traces
yarn run v1.22.19
warning package.json: No license field
$ /home/chinmay/dev/governance/node_modules/.bin/hardhat node --show-stack-traces
Nothing to compile
No need to generate any newer typings.
----------------------------------------------------
Deploying GovernanceToken and waiting for confirmations...
Error HH604: Error running JSON-RPC server: ERROR processing /home/chinmay/dev/governance/deploy/deploy-Governance-token.ts:
TypeError: Cannot read properties of undefined (reading 'length')
    at getFrom (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/helpers.ts:1713:14)
    at _deploy (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/helpers.ts:533:9)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async _deployOne (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/helpers.ts:1004:16)
    at async Object.deployGovernanceToken [as func] (/home/chinmay/dev/governance/deploy/deploy-Governance-token.ts:14:27)
    at async DeploymentsManager.executeDeployScripts (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1219:22)
    at async DeploymentsManager.runDeploy (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
    at async SimpleTaskDefinition.action (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/index.ts:438:5)
    at async Environment._runTaskDefinition (/home/chinmay/dev/governance/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at async Environment.run (/home/chinmay/dev/governance/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)

@zeuslawyer Here is the deploy script itself:

import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import verify from "../helper-functions";
import { networkConfig, developmentChains } from "../helper-hardhat-config";
import { ethers } from "hardhat";

const deployGovernanceToken: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
  // @ts-ignore
  const { getNamedAccounts, deployments, network } = hre;
  const { deploy, log } = deployments;
  const { deployer } = await getNamedAccounts();
  log("----------------------------------------------------");
  log("Deploying GovernanceToken and waiting for confirmations...");
  const governanceToken = await deploy("GovernanceToken", {
    from: deployer,
    args: [],
    log: true,
  });
  log(`dkekdoek`);
  log(`GovernanceToken at ${governanceToken.address}`);
};



export default deployGovernanceToken;
commented

So i see a couple of things:

  1. your hardhat config is exporting two objects, one with the solidity compiler and the other with the actual config object.

  2. your config object does not have the namedAccounts:{} object with the deployer property.

So your deployment script is probably getting undefined as the value of deployer when it runs this line const { deployer } = await getNamedAccounts();

When you have access to a canonical reference implementation, a good way to troubleshoot these things is to:

  1. copy and paste the canonical code and see which file is causing issues,
  2. then running a text comparison tool to see the diffs. You can do this using command line etc, but its often just easier to use another tool -- i use beyond compare (free version) to compare code quickly and see what i'm doing wrong.

Good luck and keep hacking!

@zeuslawyer Thanks so much!!!!