full-blockchain-solidity-course-js icon indicating copy to clipboard operation
full-blockchain-solidity-course-js copied to clipboard

Lesson 7 error : "before each" hook for "should set the aggregator address correctly": TypeError: ethers.getContract is not a function

Open wbshobhit1 opened this issue 2 years ago • 1 comments

Discussed in https://github.com/smartcontractkit/full-blockchain-solidity-course-js/discussions/6483

Originally posted by wbshobhit1 March 6, 2024 `const { assert } = require("chai"); const { getNamedAccounts, deployments, ethers } = require("hardhat");

describe("FundMe", async function () { let fundMe; let deployer; let mockV3Aggregator; 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("should set the aggregator address correctly", async function () {
        const response = await fundMe.priceFeed();
        assert.equal(response, mockV3Aggregator.target);
    });
});

}); `

I am getting this error "TypeError: ethers.getContract is not a function" i have tried all the possible solution present on the StackOverflow and ethetruem stack solution no solution seems to work.

wbshobhit1 avatar Mar 06 '24 11:03 wbshobhit1

Hello @wbshobhit1 Try ether.getContractFactory("FundMe).then((factory) => factory.deploy(deployer))

mrxain699 avatar May 07 '24 14:05 mrxain699