PatrickAlphaC / hardhat-fund-me-fcc

82 stars 182 forks source link

Typescript Error: ethers.getContract is not a function #168

Closed ezescigo closed 1 year ago

ezescigo commented 1 year ago

Hi guys! I'm having little trouble with this one, if someone could help me I'd appreciate it!!

I already installed hardhat-deploy-ethers as follows:

"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",

on my FundMe.test.ts

import { assert } from "chai"
import { deployments, ethers, getNamedAccounts } from "hardhat"

describe("FundMe", async () => {
    let fundMe: any
    let deployer
    let MockV3Aggregator: any
    beforeEach(async () => {
        // deploy fundMe contract using hardhat-deploy
        const accounts = await ethers.getSigners()
        deployer = (await getNamedAccounts()).deployer
        await deployments.fixture(["all"])
        fundMe = await ethers.getContract("FundMe")              //// <<<========= Error in this line
        MockV3Aggregator = await ethers.getContractFactory("MockV3Aggregator")
    })
    describe("constructor", async () => {
        it("sets the aggregator addresses correctly", async () => {
            const response = await fundMe.priceFeed()
            assert.equal(response, MockV3Aggregator.address)
        })
    })
})

The error states:

Property 'getContract' does not exist on type 'typeof import("/home/ezescigo/projects/hardhat-fundme/node_modules/ethers/lib.commonjs/ethers") & HardhatEthersHelpers'. Did you mean 'getContractAt'?ts(2551)
hardhat.d.ts(40, 5): 'getContractAt' is declared here.

Thank you!

ezescigo commented 1 year ago

Oh, I just found this topic with the solution (installing hardhat-waffle or using .getContractAt()):

https://ethereum.stackexchange.com/questions/139409/hardhat-deploy-typeerror-ethers-getcontract-is-not-a-function

        // fundMe = await ethers.getContract("FundMe")
        const fundMeContract = await deployments.get("FundMe")
        fundMe = await ethers.getContractAt(fundMeContract.abi, fundMeContract.address)