I'm Following Patrick Collins's Blockchain Course from Youtube. On lesson 07 at timestamp 11:18:00, I run the following command to run test

yarn hardhat test

I get the following error

1) "before each" hook for "sets the aggregator addresses correctly"
TypeError: ethers.getContract is not a function

following is my Solidity code

const { deployments, getNamedAccounts, network } = require("hardhat")
const { assert, expect } = require("chai")
const { ethers } = require("ethers")
const { developmentChains } = require("../../helper-hardhat-config")

describe("FundMe", function () {
    let fundMe
    let mockV3Aggregator
    let deployer
    beforeEach(async () => {
        deployer = (await getNamedAccounts()).deployer
        await deployments.fixture(["all"])
        fundMe = await ethers.getContract("FundMe", deployer)
        mockV3Aggregator = await ethers.getContract(
    describe("constructor", function () {
        it("sets the aggregator addresses correctly", async () => {
            const response = await fundMe.getPriceFeed()
            assert.equal(response, mockV3Aggregator.address)
    describe("fund", function () {
        it("Fails if you dont send enough ETH", async () => {
            await expect(fundMe.fund()).to.be.revertedWith(
                "You need to spend more ETH!"

1 Answer 1


If the answer here about installing hardhat-deploy-ethers doesn't work for you,

You could either try using .getContractAt for "ethers v6" or adding these statements to your hardhat.config.js file.


Additional details can be found in the "Discussions" section of the course repo here

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.