PatrickAlphaC / hardhat-smartcontract-lottery-fcc

MIT License
117 stars 182 forks source link

Chapter 9 - hardhat lottery: TypeError: Cannot read properties of undefined (reading 'utils') #140

Closed techybolek closed 1 year ago

techybolek commented 1 year ago

This is what I'm getting when trying to deploy my raffle contract. It looks like I'm missing a package related to hardhat/ethers. However, I'm not sure what it would be, since I've copied package.json from Patrick's repo:

yarn hardhat deploy
yarn run v1.22.19
$ /home/tromanow/patrick/lottery/backend/node_modules/.bin/hardhat deploy
LOCAL_PK: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
GOERLI_PK: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
Nothing to compile
An unexpected error occurred:

Error: ERROR processing skip func of /home/patrick/lottery/backend/deploy/01-deploy-raffle.js:
TypeError: Cannot read properties of undefined (reading 'utils')
    at Object.<anonymous> (/home/patrick/lottery/backend/deploy/01-deploy-raffle.js:5:29)
    at Module._compile (node:internal/modules/cjs/loader:1165:14)

Here is my 01-deploy-raffle.js:

const { networkConfig, developmentChains } = require('../helper-hardhat-config')
const { network, ethers } = require('hardhat')
const { verify } = require('../utils/verify')

const ENTRANCE_FEE = ethers.utils.parseEther('0.01')
const MOCK_VRF_SUB_FUND = ethers.utils.parseEther('30')

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

    let vrfCoordinatorAddress, subscriptionId
    if (developmentChains.includes(network.name)) {
        log('Local network detected, using mock vrf coordinator...')
        //const mockUsdAggregator = await deployments.get('MockV3Aggregator')
        const mockVRFCoordinator = await ethers.getContract("VRFCoordinatorV2Mock")
        vrfCoordinatorAddress = mockVRFCoordinator.address
        const txResponse = await mockVRFCoordinator.createSubscription()
        const txReceipt = await txResponse.wait(1)
        subscriptionId = txReceipt.events[0].args[0].subId
        await mockVRFCoordinator.fundSubscription(subscriptionId, MOCK_VRF_SUB_FUND)
    } else {
        return 0;
        vrfCoordinatorAddress = ourNetConfig['vrfCoordinatorV2']
        subscriptionId = ourNetConfig['subscriptionId']
    }

    const RAFFLE_ARGS = [ENTRANCE_FEE,
        vrfCoordinatorAddress,
        ourNetConfig['gasLane'],
        subscriptionId,
        RAFFLE_INTERVAL,
        ourNetConfig['callbackGasLimit']
    ]

    const raffle = await deploy('Raffle', {
        from: deployer,
        args: RAFFLE_ARGS,
        log: true,
        waitConfirmations: network.blockConfirmations || 1
    })

    console.log('Raffle Deployed')
    if (!developmentChains.includes(network.name) && process.env.ETHERSCAN_API_KEY) {
        await verify(raffle.address, RAFFLE_ARGS)
    }
}

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

Here is my package.json:

{
    "name": "hardhat-smartcontract-lottery-fcc",
    "version": "1.0.0",
    "description": "",
    "scripts": {
      "test": "yarn hardhat test",
      "test-staging": "yarn hardhat test --network goerli",
      "lint": "yarn solhint 'contracts/*.sol'",
      "lint:fix": "yarn solhint 'contracts/**/*.sol' --fix",
      "format": "yarn prettier --write .",
      "coverage": "yarn hardhat coverage"
    },
    "license": "MIT",
    "devDependencies": {
      "@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.3.0-beta.13",
      "@nomiclabs/hardhat-etherscan": "^3.0.0",
      "@nomiclabs/hardhat-waffle": "^2.0.1",
      "chai": "^4.3.4",
      "ethereum-waffle": "^3.4.0",
      "ethers": "^5.5.1",
      "hardhat": "^2.6.7",
      "hardhat-contract-sizer": "^2.4.0",
      "hardhat-deploy": "^0.9.29",
      "hardhat-gas-reporter": "^1.0.7",
      "prettier": "^2.4.1",
      "prettier-plugin-solidity": "^1.0.0-beta.19",
      "solhint": "^3.3.6",
      "solidity-coverage": "^0.7.13"
    },
    "dependencies": {
      "@chainlink/contracts": "^0.5.1",
      "@chainlink/token": "^1.1.0",
      "@openzeppelin/contracts": "^4.5.0",
      "babel-eslint": "^10.1.0",
      "dotenv": "^10.0.0"
    },
    "mocha": {
      "timeout": 10000000
    }
  }
techybolek commented 1 year ago

Solved. I was missing a require for hardhat-waffle:

require("@nomiclabs/hardhat-waffle")

PatrickAlphaC commented 1 year ago

Thanks! Do we need to update the repo?

Chinwuba22 commented 1 year ago

Please I'm having a similar issue while deploying and can't seem to locate the issue, our deploy raffle file also seems to be same...

yarn hardhat deploy yarn run v1.22.19 $ /home/uba/hardhat-smartcontract-lottery/node_modules/.bin/hardhat deploy Nothing to compile An unexpected error occurred:

Error: ERROR processing skip func of /home/uba/hardhat-smartcontract-lottery/deploy/01-deploy-raffle.js: TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider') at Object. (/home/uba/hardhat-smartcontract-lottery/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:4:61) at Module._compile (node:internal/modules/cjs/loader:1103:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:102:18)

PatrickAlphaC commented 1 year ago

Can you:

  1. Make this a discusson on the full repo? https://github.com/smartcontractkit/full-blockchain-solidity-course-js/
  2. Follow this section for formatting questions? https://www.youtube.com/watch?t=19846&v=gyMwXuJrbJQ&feature=youtu.be
Chinwuba22 commented 1 year ago

Can you:

  1. Make this a discusson on the full repo? https://github.com/smartcontractkit/full-blockchain-solidity-course-js/
  2. Follow this section for formatting questions? https://www.youtube.com/watch?t=19846&v=gyMwXuJrbJQ&feature=youtu.be

Thanks. Found my way around it.