PatrickAlphaC / hardhat-fund-me-fcc

83 stars 184 forks source link

Error: No Contract deployed with name FundMe, When writing fund.js script #29

Closed niraj2998 closed 2 years ago

niraj2998 commented 2 years ago

When started writing the code in script folder in file fund.js for funding the contract. I have written exact code as shown in the video tutorial but still it it giving me the error Error: No Contract deployed with name FundMe. Here is the code for the reference

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

async function main() {
    let deployer
    let fundMe
    deployer = (await getNamedAccounts()).deployer
    // await deployments.fixture(["all"])
    fundMe = await ethers.getContract("FundMe", deployer)
    console.log(`Got contract FundMe at ${fundMe.address}`)
    console.log("Funding contract...")
    const transactionResponse = await fundMe.fund({
        value: ethers.utils.parseEther("0.1"),
    })
    await transactionResponse.wait()
    console.log("Funded!")
}

main()
    .then(() => process.exit(0))
    .catch((error) => {
        console.error(error)
        process.exit(1)
    })

When i am using await deployments.fixture(["all"]) it is working correctly. So is it wrong to use fixture to solve this problem ? should i use some another method or way to resolve it ?

PatrickAlphaC commented 2 years ago

You're supposed to use the fixture!

The fixture is what deploys the FundMe contract!