PatrickAlphaC / hardhat-fund-me-fcc

82 stars 183 forks source link

TypeError: ethers.getContract is not a function #102

Closed bvdaniel closed 1 year ago

bvdaniel commented 1 year ago

Hi, on timestamp 11:17:00, when Patrick is testing Hardhat FundMe I'm finding this error:

FundMe
    constructor

      1) "before each" hook for "sets the aggregator addresses correctly"

  0 passing (1s)
  1 failing

  1) FundMe
       "before each" hook for "sets the aggregator addresses correctly":
     TypeError: ethers.getContract is not a function
      at Context.<anonymous> (test/staging/unit/FundMe.test.js:12:31)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at runNextTicks (node:internal/process/task_queues:65:3)
      at listOnTimeout (node:internal/timers:528:9)
      at processTimers (node:internal/timers:502:7)

And the file FundMe.test.js looks like this:

const { assert } = require("chai")
const { deployments, ethers, getNamedAccounts } = require("hardhat")

describe("FundMe", async function () {
    let fundMe
    let deployer
    beforeEach(async function () {
        // const accounts = await ethers.getSigners()
        // const accountZero = accounts[0]
        deployer = (await getNamedAccounts()).deployer
        await deployments.fixture(["all"])
        fundMe = await ethers.getContract("FundMe", deployer)
        mockV3Aggregator = await ethers.getContract(
            "MockV3Aggregator",
            deployer
        )
    })

    describe("constructor", async function () {
        it("sets the aggregator addresses correctly", async function () {
            const response = await fundMe.priceFeed()
            assert.equal(response, mockV3Aggregator.address)
        })
    })
})

VSCode suggest: "Property 'getContract' may not exist on type 'typeof import". Did you mean 'getContractAt'?

But getContractAt seems to do something else.

PatrickAlphaC commented 1 year ago

Run:

yarn add hardhat-deploy-ethers

Or

npm i hardhat-deploy-ethers

And make sure you have require("hardhat-deploy") in your hardhat.config.js

BilgeKaanGencdogan commented 2 months ago

Run:

yarn add hardhat-deploy-ethers

Or

npm i hardhat-deploy-ethers

And make sure you have require("hardhat-deploy") in your hardhat.config.js

those things that you recommended, @PatrickAlphaC, did not work for me. Instead, I have added

require("@nomiclabs/hardhat-ethers")

manually into my hardhat.config.js. It worked. Solution link: https://ethereum.stackexchange.com/questions/130125/solvedpatrickcollins-solidity-course-2022-lesson-7-112038-typeerror-e Just for your info. Thanks