Giter Site home page Giter Site logo

hardhat-fund-me-fcc's Introduction

Update: Head to Cyfrin Updraft

ℹ️ Important: This repo is no longer maintained; we invite all people learning Solidity to head to Cyfrin Updraft! The 100% free #1 smart contract education platform on earth.

Hardhat Fund Me

This repo has been updated to work with Sepolia Testnet over Goerli.

This is a section of the Javascript Blockchain/Smart Contract FreeCodeCamp Course.

⌨️ (10:00:48) Lesson 7: Hardhat Fund Me

Full Repo

This project is apart of the Hardhat FreeCodeCamp video.

Getting Started

Requirements

  • git
    • You'll know you did it right if you can run git --version and you see a response like git version x.x.x
  • Nodejs
    • You'll know you've installed nodejs right if you can run:
      • node --version and get an ouput like: vx.x.x
  • Yarn instead of npm
    • You'll know you've installed yarn right if you can run:
      • yarn --version and get an output like: x.x.x
      • You might need to install it with npm or corepack

Quickstart

git clone https://github.com/PatrickAlphaC/hardhat-fund-me-fcc
cd hardhat-fund-me-fcc
yarn

Typescript

For the typescript edition, run:

git checkout typescript

Optional Gitpod

If you can't or don't want to run and install locally, you can work with this repo in Gitpod. If you do this, you can skip the clone this repo part.

Open in Gitpod

Usage

Deploy:

yarn hardhat deploy

Testing

yarn hardhat test

Test Coverage

yarn hardhat coverage

Deployment to a testnet or mainnet

  1. Setup environment variables

You'll want to set your SEPOLIA_RPC_URL and PRIVATE_KEY as environment variables. You can add them to a .env file, similar to what you see in .env.example.

  • PRIVATE_KEY: The private key of your account (like from metamask). NOTE: FOR DEVELOPMENT, PLEASE USE A KEY THAT DOESN'T HAVE ANY REAL FUNDS ASSOCIATED WITH IT.
  • SEPOLIA_RPC_URL: This is url of the seplia testnet node you're working with. You can get setup with one for free from Alchemy
  1. Get testnet ETH

Head over to faucets.chain.link and get some tesnet ETH. You should see the ETH show up in your metamask.

  1. Deploy
yarn hardhat deploy --network sepolia

Scripts

After deploy to a testnet or local net, you can run the scripts.

yarn hardhat run scripts/fund.js

or

yarn hardhat run scripts/withdraw.js

Estimate gas

You can estimate how much gas things cost by running:

yarn hardhat test

And you'll see and output file called gas-report.txt

Estimate gas cost in USD

To get a USD estimation of gas cost, you'll need a COINMARKETCAP_API_KEY environment variable. You can get one for free from CoinMarketCap.

Then, uncomment the line coinmarketcap: COINMARKETCAP_API_KEY, in hardhat.config.js to get the USD estimation. Just note, everytime you run your tests it will use an API call, so it might make sense to have using coinmarketcap disabled until you need it. You can disable it by just commenting the line back out.

Verify on etherscan

If you deploy to a testnet or mainnet, you can verify it if you get an API Key from Etherscan and set it as an environemnt variable named ETHERSCAN_API_KEY. You can pop it into your .env file as seen in the .env.example.

In it's current state, if you have your api key set, it will auto verify sepolia contracts!

However, you can manual verify with:

yarn hardhat verify --constructor-args arguments.js DEPLOYED_CONTRACT_ADDRESS

Linting

solhint installation: Documentation

To check linting / code formatting:

yarn lint

or, to fix:

yarn lint:fix

Formatting

yarn format

Thank you!

If you appreciated this, feel free to follow me or donate!

ETH/Polygon/Avalanche/etc Address: 0x9680201d9c93d65a3603d2088d125e955c73BD65

Patrick Collins Twitter Patrick Collins YouTube Patrick Collins Linkedin Patrick Collins Medium

hardhat-fund-me-fcc's People

Contributors

aayush-gupta-coder avatar alymurtazamemon avatar byte14 avatar gmluqa avatar iosifv avatar joonakauranen avatar mehedi-iitdu avatar mjviana avatar othaime-en avatar patrickalphac avatar peternagy1332 avatar princeibs avatar ramansb avatar rin-st avatar robocrypter avatar rodriguesnavil avatar rohitks7 avatar shawnesquivel avatar uday03meh avatar yyc13236 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hardhat-fund-me-fcc's Issues

MockV3Aggregator not compiling

When running MockV3Aggregator it gives the error :

@chainlink/contracts/src/v0.6/interfaces/AggregatorV2V3Interface.sol:7:38: TypeError: Interfaces cannot inherit.
interface AggregatorV2V3Interface is AggregatorInterface, AggregatorV3Interface

Solution found that you could import both AggregatorInterface and AggregatorV3Interface in the Mock file, but your file doesn't have it. Is there another solution ?

Mock contract not deploying

yarn hardhat deploy

Gets the following error:

Error: cannot get the transaction for MockV3Aggregator's previous deployment, please check your node synced status.

As in the course, I am using the hardhat network (not localhost). Following the deployment of the mock contract, which is stored inside ./contracts/test:

await deploy("MockV3Aggregator", {
            contract: "MockV3Aggregator",
            from: deployer,
            log: true,
            args: [DECIMALS, INITIAL_ANSWER],
        })

Thank you in advance

Staging test not exiting

yarn hardhat test --network rinkeby
when i checked the etherscan everything seems to be fine, but my tests are not ending, i also tried console.logging the endingBalance it does return me zero which is correct but the tests are not ending.

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

developmentChain.includes(network.name)? describe.skip
: describe("FundMe", async function () {
      let fundMe
      let deployer
      const sendValue = ethers.utils.parseEther("1")

      beforeEach(async function () {
          deployer = (await getNamedAccounts()).deployer
          fundMe = await ethers.getContract("FundMe", deployer)
      })

      it("allows people to fund and withdraw", async function () {
          await fundMe.fund({ value: sendValue })
          await fundMe.withdraw()
          const endingBalance = await fundMe.provider.getBalance(
              fundMe.address
          )
          assert.equal(endingBalance.toString(), "0")
      })
  })

How does this syntax work exactly?

As I get further into the tutorial, I keep getting confused about the "extrapolation" of different variables. I understand what it does but am wondering what the logical reasoning behind this syntactical sugar is. Also, what is this method of extrapolation called?

Here is some of the confusing code:
module.exports = async ({ getNamedAccounts, deployments }),
const { networkConfig } = require("../helper-hardhat-config"),
const { network } = require("hardhat"),
const { deployer } = await getNamedAccounts.

basically, everything that uses {} when declaring a variable/parameter.

Thanks!!

fundme contract not verifying after deployment on etherscan (tried both -> auto and manually)

Fundme contract not verifying after deployment on etherscan i had tried both ways automatic and manually.

Showing this error in terminal :-

Error in plugin @nomiclabs/hardhat-etherscan: The constructor for contracts/FundMe.sol:FundMe has 1 parameters but 0 arguments were provided instead

01-deploy-fundme.js

const { isAddress } = require("ethers/lib/utils");
const { networkConfig } = require("../helper-hardhat-config");
const { network } = require("hardhat");
const { verify } = require("../utils/verify");

module.exports = async ({ getNamedAccounts, deployments }) => {
  const { deploy, log, get } = deployments;
  const { deployer } = await getNamedAccounts();
  const chainId = network.config.chainId;

  let ethUsdPriceFeedAddress;
  if (chainId == 31337) {
    const ethUsdAggregator = await get("MockV3Aggregator");
    ethUsdPriceFeedAddress = ethUsdAggregator.address;
  } else {
    ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"];
  }

  const fundme = await deploy("FundMe", {
    from: deployer,
    args: [ethUsdPriceFeedAddress], 
    log: true,
    waitConfirmations: network.config.blockConfirmations || 1, 
  });

  if (chainId !== 31337 && process.env.ETHERSCAN_API_KEY) {
    await verify(fundme.address, [ethUsdPriceFeedAddress]);
  }
  log("------------------------------------------");
};

module.exports.tags = ["all", "fundme"];

verify.js

const { run } = require("hardhat");

const verify = async (contractAddress, args) => {
  console.log("Verifying contract...");

  try {
    await run("verify:verify", {
      address: contractAddress,
      construtorArguments: args,
    });
  } catch (e) {
    if (e.message.toLowerCase().includes("already verified")) {
      console.log("Already verified!!");
    } else {
      console.log(e);
    }
  }
};

module.exports = { verify };

and I double checked .env and hardhat.config, they are same what patrick had done in video

Error HH16: The directory C:\Users\PC contains files that could conflict:

I tried creating a new project with advanced sample project and i got the below error:

can some one tell me how to resolve this?

Welcome to Hardhat v2.9.9

√ What do you want to do? · Create an advanced sample project
√ Hardhat project root: · C:\Users\PC
√ Do you want to add a .gitignore? (Y/n) · y
Error HH16: The directory C:\Users\PC contains files that could conflict:

contracts
scripts
test

Either try using a new directory, or remove the files listed above.

yarn hardhat deploy --tags

yarn run v1.22.18
warning package.json: No license field
warning ../../../package.json: No license field
$ '/Users/mubashirhussain/Desktop/course.ss/harhat Fund me/node_modules/.bin/hardhat' deploy --tags
Error HH306: The '--tags' parameter expects a value, but none was passed.

For more info go to https://hardhat.org/HH306 or run Hardhat with --show-stack-traces
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

00-deploy-mocks,js

const { network } = require("hardhat")

const DECIMALS = "8"
const INITIAL_PRICE = "200000000000" // 2000
module.exports = async ({ getNamedAccounts, deployments }) => {
    const { deploy, log } = deployments
    const { deployer } = await getNamedAccounts()
    const chainId = network.config.chainId
    // If we are on a local develohelppment network, we need to deploy mocks!
    if (chainId == 31337) {
        log("Local network detected! Deploying mocks...")
        await deploy("MockV3Aggregator", {
            contract: "MockV3Aggregator",
            from: deployer,
            log: true,
            args: [DECIMALS, INITIAL_PRICE],
        })
        log("Mocks Deployed!")
        log("------------------------------------------------")
        log(
            "You are deploying to a local network, you'll need a local network running to interact"
        )
        log(
            "Please run `npx hardhat console` to interact with the deployed smart contracts!"
        )
        log("------------------------------------------------")
    }
}
module.exports.tags = ["all", "mocks"]

TypeError: Cannot read properties of undefined (reading 'ethUsdPriceFeed')

yarn hardhat deploy --network rinkeby deploy error

 yarn run v1.22.15
warning package.json: No license field
$ /home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/.bin/hardhat deploy --network rinkeby
Nothing to compile
An unexpected error occurred:

Error: ERROR processing /home/eemcs/freecodecamp/hardhat-fund-me-cc/deploy/01-deploy-fund-me.js:
TypeError: Cannot read properties of undefined (reading 'ethUsdPriceFeed')
    at Object.module.exports.default [as func] (/home/eemcs/freecodecamp/hardhat-fund-me-cc/deploy/01-deploy-fund-me.js:17:56)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at DeploymentsManager.executeDeployScripts (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1219:22)
    at DeploymentsManager.runDeploy (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
    at SimpleTaskDefinition.action (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/index.ts:438:5)
    at Environment._runTaskDefinition (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at Environment.run (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at SimpleTaskDefinition.action (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/index.ts:584:32)
    at Environment._runTaskDefinition (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at Environment.run (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at DeploymentsManager.executeDeployScripts (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at DeploymentsManager.runDeploy (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
    at SimpleTaskDefinition.action (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/index.ts:438:5)
    at Environment._runTaskDefinition (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at Environment.run (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at SimpleTaskDefinition.action (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/index.ts:584:32)
    at Environment._runTaskDefinition (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at Environment.run (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at SimpleTaskDefinition.action (/home/eemcs/freecodecamp/hardhat-fund-me-cc/node_modules/hardhat-deploy/src/index.ts:669:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

01-deploy-fund-me.js

const { getNamedAccounts, deployments, network } = require("hardhat")
const { networkConfig, developmentChains } = require("../helper-hardhat-config")
const { verify } = require("../utils/verify")

module.exports.default = async ({ getNamedAccounts, deployments }) => {
    const { deploy, log } = deployments
    const { deployer } = await getNamedAccounts()
    const chainId = network.config.chainId

    //const addres = "0x8A753747A1Fa494EC906cE90E9f37563A8AF630e"

    let ethUsdPriceFeedAddress
    if (developmentChains.includes(network.name)) {
        const ethUsdAggregator = await deployments.get("MockV3Aggregator")
        ethUsdPriceFeedAddress = ethUsdAggregator.address
    } else {
        ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"]
    }

    const args = [ethUsdPriceFeedAddress]
    const fundMe = await deploy("FundMe", {
        from: deployer,
        args: args,
        log: true,
        waitConfirmation: network.config.blockConfirmations || 1,
    })

    if (
        !developmentChains.includes(network.name) &&
        process.env.ETHERSCAN_API_KEY
    ) {
        await verify(fundMe.address, args)
    }
    log("________________________________________________________")
}

module.exports.tags = ["all", "fundme"]

helper-hardhat-config.js

const networkConfig = {
    4: {
        name: "rinkeby",
        ethUsdPriceFeed: "0x8A753747A1Fa494EC906cE90E9f37563A8AF630e",
    },
    137: {
        name: "polygon",
        ethUsdPriceFeed: "0xF9680D99D6C9589e2a93a78A04A279e509205945",
    },
}
const developmentChains = ["hardhat", "localhost"]
const DECIMALS = 8
const INITAL_ANSWER = 200000000000

module.exports = {
    networkConfig,
    developmentChains,
    DECIMALS,
    INITAL_ANSWER,
}

Can't deploy 99-deploy-storage-fun.js

When I run command

yarn hardhat deploy --tags storage

I'm getting error

Deploying FunWithStorage and waiting for confirmations...
deploying "FunWithStorage" (tx: 0xf2ce2ca8b8683ca2c6cf0b485fc0881c410149a34ac64c5c6ae9a853175ee4b4)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 227342 gas
Logging storage...
An unexpected error occurred:

Error: ERROR processing /home/szymon/hh-fcc/hardhat-fund-me-fcc/deploy/99-deploy-storage-fun.js:
InvalidArgumentsError: Errors encountered in param 1: Invalid value "0x0000000000000000000000000000000000000000000000000000000000000000" supplied to : QUANTITY
    at validateParams (/home/szymon/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/jsonrpc/types/input/validation.ts:64:13)
    at EthModule._getStorageAtParams (/home/szymon/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:688:26)
    at EthModule.processRequest (/home/szymon/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:184:49)
    at HardhatNetworkProvider._send (/home/szymon/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:194: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)
    at HardhatNetworkProvider.request (/home/szymon/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:117:18)
    at EthersProviderWrapper.send (/home/szymon/hh-fcc/hardhat-fund-me-fcc/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)
    at DeploymentsManager.executeDeployScripts (/home/szymon/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19)
    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)
    at DeploymentsManager.runDeploy (/home/szymon/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
    at SimpleTaskDefinition.action (/home/szymon/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/index.ts:438:5)
    at Environment._runTaskDefinition (/home/szymon/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14)
    at Environment.run (/home/szymon/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:129:14)
    at SimpleTaskDefinition.action (/home/szymon/hh-fcc/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/index.ts:584:32)
error Command failed with exit code 1.

I found that problem is in file 99-deploy-storage-fun.js. More precisely in function inside for loop

await ethers.provider.getStorageAt( funWithStorage.address, i )

When I delete this function or change it to something other I don't have error.

How should I fix this error?

FundMe project isn't deploying and getting "No deployment found for: MockV3Aggregator" error

When I run this command yarn hardhat deploy --tags fundme I'm getting this MockV3Aggregator error.

Error: ERROR processing /Users/mohameduzair/blockChain/JSweb3_2/fundMe_hardhat/deploy/01-deploy-fundMe.js:
Error: No deployment found for: MockV3Aggregator at Object.get (/Users/mohameduzair/blockChain/JSweb3_2/fundMe_hardhat/node_modules/hardhat-deploy/src/DeploymentsManager.ts:162:17)

01-deploy-fundMe.js deploy script

const { network, deployments, getNamedAccounts } = require("hardhat")
const { networkConfig, developmentChains } = require("../helper-hardhat-config")

module.exports = async ({ getNamedAccounts, deployments }) => {
    const { deploy, log } = deployments
    const { deployer } = await getNamedAccounts()
    const chainId = network.config.chainId

    // when we going for localhost or hardhat network we want to use mock
    // ?selecting the correct pricefeed address
    let ethUsdPriceFeedAddress
    if (developmentChains.includes(network.name)) {
        // if (chainId === 31337) {
        const ethUsdAggregator = await deployments.get("MockV3Aggregator")
        ethUsdPriceFeedAddress = ethUsdAggregator.address
    } else {
        ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"]
    }

    const fundMe = await deploy("FundMe", {
        from: deployer,
        args: [ethUsdPriceFeedAddress],
        log: true,
    })
    log(`FundMe deployed at ${fundMe.address}`)
    log(`-------------------------!!!--------------------------`)
}
module.exports.tags = ["all", "fundme"] 

MockV3Aggregator.sol contract

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
// pragma solidity >=0.6.6 <0.8.7;
import "@chainlink/contracts/src/v0.6/tests/MockV3Aggregator.sol";

Thank you

No Contract deployed with Name "FundMe"

while creating unit test for FundMe Contract, I have got this error.

Error: No Contract deployed with name FundMe

The testing code is below

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

describe("FundMe", async function() {
    let fundMe
    let deployer
    let mockV3Aggregator
    beforeEach(async function() {
        // const { accounts } = await ethers.getSigners()
        // const accountsZero = accounts[0]
        deployer = (await getNamedAccounts()).deployer
        deployments.fixture(["all"])
        fundMe = await ethers.getContract("FundMe", deployer)
        mockV3Aggregator = await ethers.getContract(
            "MockV3Aggregator",
            deployer
        )
    })
    describe("constructor", async function() {
        it("Sets the Aggregator address correctly", async function() {
            const response = await fundMe.priceFeed()
            assert.equal(response, mockV3Aggregator.address)
        })
    })
})

I have checked the deployments folder and it too show the deployments have been made:
Screenshot from 2022-07-23 16-52-26
The full error is as follows:

  FundMe
    constructor

      1) "before each" hook for "Sets the Aggregator address correctly"


  0 passing (1s)
  1 failing

  1) FundMe
       "before each" hook for "Sets the Aggregator address correctly":
     Error: No Contract deployed with name FundMe
      at Object.getContract (node_modules/@nomiclabs/hardhat-ethers/src/internal/helpers.ts:447:11)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at Context.<anonymous> (test/unit/FundMe.test.js:13:18)



error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I have tried redeploying using yarn hardhat deploy and deploy happens without any error, but test still doesn't detect the deployments.
I have tried other hit and trials methods too, but no luck.
Does anyone know some troublsheeoting tips.

Can't deploy mockV3Aggregator

Hello i have problems with: 01-deploy-fund me (npx hardhat deploy --tags fundme)

Error: ERROR processing /Users/dervoo/Kontrakty/deploy/01-deploy-FundMe.js:
Error: No deployment found for: MockV3Aggregator
at Object.get (/Users/dervoo/Kontrakty/node_modules/hardhat-deploy/src/DeploymentsManager.ts:162:17)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at Object.module.exports [as func] (/Users/dervoo/Kontrakty/deploy/01-deploy-FundMe.js:12:34)
at DeploymentsManager.executeDeployScripts (/Users/dervoo/Kontrakty/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1219:22)
at DeploymentsManager.runDeploy (/Users/dervoo/Kontrakty/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
at SimpleTaskDefinition.action (/Users/dervoo/Kontrakty/node_modules/hardhat-deploy/src/index.ts:438:5)
at Environment._runTaskDefinition (/Users/dervoo/Kontrakty/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
at Environment.run (/Users/dervoo/Kontrakty/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)

const { networkConfig } = require("../helper-hardhat-config")
const { network } = require("hardhat")
const { verify } = require("../utils/verify")
const { developmentChains } = require("../helper-hardhat-config")

module.exports = async ({ getNamedAccounts, deployments }) => {
    const { deploy, log } = deployments
    const { deployer } = await getNamedAccounts()
    const chainId = network.config.chainId

    // const ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"]
    let ethUsdPriceFeedAddress
    if(developmentChains.includes(network.name)) {
        const ethUsdAggregator = await deployments.get("MockV3Aggregator")
        ethUsdPriceFeedAddress = ethUsdAggregator.address
    } else {
        ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"]
    }
    const args = [ethUsdPriceFeedAddress]
    const fundMe = await deploy("FundMe", {
        from: deployer,
        args: [ethUsdPriceFeedAddress],
        log: true,
        waitConfirmations: network.config.blockConfirmations || 1,
    })
    if(!developmentChains.includes(network.name) && process.env.ETHERSCAN_API_KEY) {
        await verify(fundMe.address, args)
    }
}
module.exports.tags = ["all", "fundme"]

following by error in test:

ERROR processing /Users/dervoo/Kontrakty/deploy/01-deploy-FundMe.js:
Error: No deployment found for: mockV3Aggregator
    at Object.get (/Users/dervoo/Kontrakty/node_modules/hardhat-deploy/src/DeploymentsManager.ts:162:17)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Object.module.exports [as func] (/Users/dervoo/Kontrakty/deploy/01-deploy-FundMe.js:15:34)
    at DeploymentsManager.executeDeployScripts (/Users/dervoo/Kontrakty/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1219:22)
    at DeploymentsManager.runDeploy (/Users/dervoo/Kontrakty/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
    at Object.fixture (/Users/dervoo/Kontrakty/node_modules/hardhat-deploy/src/DeploymentsManager.ts:315:9)
    at Context.<anonymous> (/Users/dervoo/Kontrakty/test/staging/unit/FundMe.test.js:17:9)

AND while trying to deploy:

Error: ERROR processing /Users/dervoo/Kontrakty/deploy/01-deploy-FundMe.js:
TypeError: Cannot read properties of undefined (reading 'length')

[Solidity] Retrieving slots and values for Arrays and Mappings

Hi,

First of all many thanks for this great course on hardhat & solidity.
I am following lesson 7: Hardhat fund me but I cannot figure how to find slots and value for mappings & arrays cf : comments from deploy script

0. Solidity Code

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract FunWithStorage {
    uint256 favoriteNumber; // Stored at slot 0
    bool someBool; // Stored at slot 1
    uint256[] myArray; /* Array Length Stored at slot 2,
    but the objects will be the keccak256(2), since 2 is the storage slot of the array */
    mapping(uint256 => bool) myMap; /* An empty slot is held at slot 3
    and the elements will be stored at keccak256(h(k) . p)
    p: The storage slot (aka, 3)
    k: The key in hex
    h: Some function based on the type. For uint256, it just pads the hex
    */
    uint256 constant NOT_IN_STORAGE = 123;
    uint256 immutable i_not_in_storage;

    constructor() {
        favoriteNumber = 25; // See stored spot above // SSTORE
        someBool = true; // See stored spot above // SSTORE
        myArray.push(222); // SSTORE
        myMap[0] = true; // SSTORE
        i_not_in_storage = 123;
    }

    function doStuff() public {
        uint256 newVar = favoriteNumber + 1; // SLOAD
        bool otherVar = someBool; // SLOAD
        // ^^ memory variables
    }
}

1. Array stuff

To retrieve slots for uint256[] myArray (position = 2 ; cf: Solidity code)

I am using the following code :

  const arrayPositionInStore = 2;
  const arraySlot = ethers.utils.keccak256(ethers.utils.hexlify(arrayPositionInStore));
  const arrayValue = await ethers.provider.getStorageAt(
    funWithStorage.address,
    ethers.utils.keccak256(ethers.utils.hexlify(2)),
  );

However arrayValue is :

'0x0000000000000000000000000000000000000000000000000000000000000000'

While I am expecting 222 here.

2. Mapping stuff

To retrieve slots for uint256[] myArray (position = 3 ; cf: Solidity code)

I am using the following code :

  const mappingPositionInStore = 3;
  const key = 0;
  const mapKeyInStore = ethers.utils.keccak256(
    ethers.utils.concat([
      ethers.utils.hexlify(mappingPositionInStore),
      ethers.utils.hexlify(key),
    ]),
  );

  const mappingValue = await ethers.provider.getStorageAt(
    funWithStorage.address,
    mapKeyInStore,
  );

However mappingValue is :

'0x0000000000000000000000000000000000000000000000000000000000000000'

while I am expecting 1 (true).

Could you please give me some pointers regarding what I am doing wrong ?

Installing Hardhat v1.22.17

Hey guys, I am having issues installing Hardhat v1.22.17 on my windows 10 PC.. On the terminal, when I run " yarn add --dev hardhat", it keeps installing the v1.22.15 version which is most likely outdated. @PatrickAlphaC installed Hardhat v1.22.17 at the beginning of this lesson but I seem to keep getting the old version which doesn't have the "advanced sample project" option.

Error! while testing fundMe fund

Error:

  1) FundMe
       fund
         Updated the amount funded data structure:
     Error: VM Exception while processing transaction: reverted with reason string 'Didn't send enough!'

The code used:

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

describe("FundMe", async function() {
    let fundMe
    let deployer
    let mockV3Aggregator
    const sendValue = ethers.utils.parseEther("1")   //1 ETH
    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)
        })
    })
    describe("fund",async function(){
        it("Fails if you don't send enough ETH", async function(){
            await expect(fundMe.fund()).to.be.reverted
        })
        it("Updated the amount funded data structure", async function(){
            await fundMe.fund({value: sendValue})
            const response = await fundMe.addressToAmountFunded(deployer)
            assert.equal(response.toString(), sendValue.toString())
        })
    })
})

Test error

Hi everythink. is working fine till we add

!developmentChains.includes(network.name)
? describe.skip
:

into tests, I'm getting error:
TypeError: Cannot read properties of undefined (reading 'includes')

I couldn't figure out what to do anybody can help ?

https://github.com/yigtkaya/hardhat-fund-me (own github link for course code)

TypeError at deploying mocks

I'm trying to deploy with this command line "yarn hardhat deploy --tags mocks", but I keep getting this error message:

Error: ERROR processing /home/jic1816/FCC-Solidity/hardhat-fund-me/deploy/00-deploy-mocks.js:
TypeError: Cannot read properties of undefined (reading 'length')

What could be the problem? The error's next lines don't point to any file that I've written but to "helpers.ts" from "hardhat-deploy". First I tried compiling the files that I wrote alongside Patrick's video, but then I also tried copying and pasting the files from github. Neither way worked.

Thank you!

PS: I didn't use the "advance sample project" in Hardhat (because of the update), but I guess it has nothing to do with this. Right?

No Contract deployed with name FundMe , Keep getting the same error from prev issue

I refer to #63
I keep getting the same error
this is what I've done as your recommendation.

my2-fund_me-hh\deployments\localhost , this folder contain deployed files completely as figure below.

image

The problem is about node_modules@nomiclabs\hardhat-ethers\src\internal\helpers.ts:447:11)

But if I deploy to Ganache or TestNet, It works well.

this is my enviroment on window laptop
node=v16.15.0
npx=1.22.19
yarn=8.5.5
hardhat =2.9.7

This is error on VS Code

Once I start the hardhat node , it deployed all of the files in the deploy folder

  1. run yarn hardhat node
    `
    D:\BC-World\BC-Dev\WEB3_JS\Patrick-JSLab\my2-fund_me-hh>yarn hardhat node
    yarn run v1.22.19
    $ D:\BC-World\BC-Dev\WEB3_JS\Patrick-JSLab\my2-fund_me-hh\node_modules.bin\hardhat node
    Nothing to compile
    Local network detected! Deploying mocks...
    deploying "MockV3Aggregator" (tx: 0x2f60bd4cba5dffe33cd22380f4891cfadb7f13aad763bb084e8a1c3336b892f9)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 569635 gas
    Mocks Deployed!

You are deploying to a local network, you'll need a local network running to interact
Run (npx hardhat console) to interact with the deployed smart contracts!

31337
Get MockV3Aggregator for fake price feed.
deploying "FundMe" (tx: 0x24bdce76b4c5093ca6c0383261efdb88f061990bc2fb1bb40a37287d724abfcf)...: deployed at 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 with 1058239 gas
FundMe deployed at 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
Started HTTP and WebSocket JSON-RPC server at http://127.0.0.1:8545/

Accounts

WARNING: These accounts, and their private keys, are publicly known.
Any funds sent to them on Mainnet or any other live network WILL BE LOST.

Account #0: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 (10000 ETH)
Private Key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

`
2. yarn hardhat run scripts/myfund.js

`
yarn run v1.22.19
$ D:\BC-World\BC-Dev\WEB3_JS\Patrick-JSLab\my2-fund_me-hh\node_modules.bin\hardhat run scripts/myfund.js
### Error: No Contract deployed with name FundMe
at Object.getContract (D:\BC-World\BC-Dev\WEB3_JS\Patrick-JSLab\my2-fund_me-hh\node_modules@nomiclabs\hardhat-ethers\src\internal\helpers.ts:447:11)
at main (D:\BC-World\BC-Dev\WEB3_JS\Patrick-JSLab\my2-fund_me-hh\scripts\myfund.js:10:18)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

`

hardhat installation

I'm having issues with hardhat installation.Even after i added --dev hardhat at terminal, there is no package.json or node modules revealed. However it's still saying "success save 1 new dependency".

Hardhat-fund-me- rinkeby deployment problem

Hi everyone,
I wrote fundme contract with hardhat with patrick. I cant deploy it on a testnet. Its working with mocks. Then I delete my code copy and paste patrick's (from github) code. Its still doesnt work.
( when I gitclone all code its working on testnets)
I copyied and paste the files : 01-deploy-fund-me.js , hardhat.config.js , helper-hardhat-config.js
When I wrote yarn hardhat deploy --network rinkeby getting this error:

Deploying FundMe and waiting for confirmations...
An unexpected error occurred:

Error: ERROR processing /home/furkansezal/delete2/deploy/01-deploy-fund-me.js:
Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.6.8)
at Logger.makeError (/home/furkansezal/delete2/node_modules/@ethersproject/logger/src.ts/index.ts:261:28)
at Logger.throwError (/home/furkansezal/delete2/node_modules/@ethersproject/logger/src.ts/index.ts:273:20)
at Web3Provider. (/home/furkansezal/delete2/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:444:23)
at step (/home/furkansezal/delete2/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:48:23)
at Object.throw (/home/furkansezal/delete2/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:29:53)
at rejected (/home/furkansezal/delete2/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:21:65)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at DeploymentsManager.executeDeployScripts (/home/furkansezal/delete2/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at DeploymentsManager.runDeploy (/home/furkansezal/delete2/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
at SimpleTaskDefinition.action (/home/furkansezal/delete2/node_modules/hardhat-deploy/src/index.ts:438:5)
at Environment._runTaskDefinition (/home/furkansezal/delete2/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
at Environment.run (/home/furkansezal/delete2/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
at SimpleTaskDefinition.action (/home/furkansezal/delete2/node_modules/hardhat-deploy/src/index.ts:584:32)
at Environment._runTaskDefinition (/home/furkansezal/delete2/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
at Environment.run (/home/furkansezal/delete2/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
at SimpleTaskDefinition.action (/home/furkansezal/delete2/node_modules/hardhat-deploy/src/index.ts:669:5)
error Command failed with exit code 1.

00-deploy-mocks gives an error: Cannot read properties of undefined (reading 'length') [Tutorial Time: 10:48:00]

So I am at moment 10:48:00 in the tutorial, and it returns me this:

An unexpected error occurred:

Error: ERROR processing C:\Users\Pc\hardhat-fund-me-fcc\deploy\00-deploy-mocks.js:
TypeError: Cannot read properties of undefined (reading 'length')

error when I try to run:
yarn hardhat deploy --tags mocks

I manually copied all the code from the tutorial in my Visual Studio and I think I got all the steps right. Here's my code:

00-deploy-mocks.js

const {network} = require("hardhat")
const {developmentChains, DECIMALS, INITIAL_ANSWER} = require("../helper-hardhat-config")
const chainId = network.config.chainId

module.exports = async({getNamedAccounts,deployments})=>{
    const {deploy,log} = deployments
    const {deployer} = await getNamedAccounts()

    if(developmentChains.includes(network.name)){
        log("Local Network detected! Deploying mocks...")
        await deploy("MockV3Aggregator", {
            contract: "MockV3Aggregator",
            from: deployer,
            log:true,
            args: [DECIMALS, INITIAL_ANSWER],
        })
        log("Mocks deployed!")
        log("-----------------------")
    }
}

module.exports.tags = ["all","mocks"]

helper-hardhat-config.js

const networkConfig = {
    4: {
        name: "rinkeyby",
        ethUsdPriceFeed: "0x8A753747A1Fa494EC906cE90E9f37563A8AF630e"

    },

    137: {
        name:"polygon",
        ethUsdPriceFeed:"0xF9680D99D6C9589e2a93a78A04A279e509205945",
    },

    
    //31337
}

const developmentChains = ["hardhat", "localhost"]
const DECIMALS = 8
const INITIAL_ANSWER = 200000000000

module.exports = {
    networkConfig,
    developmentChains,
    DECIMALS,
    INITIAL_ANSWER,
}

What am I missing? It goes beyond the first if verification so I assume it has something to do with what's beyond deploy("MockV3Aggregator",

yarn add --dev "hardhat@^2.9.3" installs 2.10.1?

I keep trying to install the version of hardhat used in the video (2.9.3) but when i run "yarn add --dev hardhat@^2.9.3" it just installs hardhat 2.10.1 anyways. I used yarn remove hardhat several times and reinstalled it, yet I still get 2.10.1.

What should I do?

Error : No Contract deployed with name FundMe once run yarn hardhat run scripts/fund.js

I clone your project and run yarn in order to install all dependency packages.
I did the following steps.

  1. npx hardhat deploy

image

  1. yarn hardhat run scripts/fund.js OR npx hardhat run scripts\fund.js

This is a Given Error
Error: No Contract deployed with name FundMe
at Object.getContract (D:\BC-World\BC-Dev\WEB3_JS\Patrick-JSLab\patrick_hardhat-fund-me\node_modules@nomiclabs\hardhat-ethers\src\internal\helpers.ts:447:11)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at main (D:\BC-World\BC-Dev\WEB3_JS\Patrick-JSLab\patrick_hardhat-fund-me\scripts\fund.js:5:18)

I imagine that it occure error from https://github.com/wighawag/hardhat-deploy-ethers#installation

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

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 ?

Hardhat-fund-me-fcc ||| rinkeby/goerli deployment problem

Lesson 7: Hardhat Fund Me
I am at roughly 10:58:49 / 1:07:54:30 in the video.

I am trying to deploy fundMe to Rinkeby (I have also tried Goerli) and I am getting the following error.

Here is the error:

Error: ERROR processing /Users/jabie/hardhat-fund-me-fcc/deploy/01-deploy-fund-me.js:
TypeError: Cannot read properties of undefined (reading 'ethUsdPriceFeed')
at Object.module.exports [as func] (/Users/jabie/hardhat-fund-me-fcc/deploy/01-deploy-fund-me.js:36:56)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at DeploymentsManager.executeDeployScripts (/Users/jabie/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1219:22)
at DeploymentsManager.runDeploy (/Users/jabie/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
at SimpleTaskDefinition.action (/Users/jabie/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/index.ts:438:5)
at Environment._runTaskDefinition (/Users/jabie/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
at Environment.run (/Users/jabie/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
at SimpleTaskDefinition.action (/Users/jabie/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/index.ts:584:32)
at Environment._runTaskDefinition (/Users/jabie/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
at Environment.run (/Users/jabie/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
at DeploymentsManager.executeDeployScripts (/Users/jabie/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at DeploymentsManager.runDeploy (/Users/jabie/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
at SimpleTaskDefinition.action (/Users/jabie/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/index.ts:438:5)
at Environment._runTaskDefinition (/Users/jabie/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
at Environment.run (/Users/jabie/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
at SimpleTaskDefinition.action (/Users/jabie/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/index.ts:584:32)
at Environment._runTaskDefinition (/Users/jabie/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
at Environment.run (/Users/jabie/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
at SimpleTaskDefinition.action (/Users/jabie/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/index.ts:669:5)
error Command failed with exit code 1.

Anyone else running into this or have an idea on what the issue is?

getContract is not found

import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"
import { assert, expect } from "chai"
import { network, deployments, ethers } from "hardhat"
import { developmentChains } from "../../helper-hardhat-config"
import { FundMe, MockV3Aggregator } from "../../typechain-types"

describe("FundMe", function () {
  let fundMe: FundMe
  let mockV3Aggregator: MockV3Aggregator
  let deployer: SignerWithAddress
  beforeEach(async () => {
    if (!developmentChains.includes(network.name)) {
      throw "You need to be on a development chain to run tests"
    }
    const accounts = await ethers.getSigners()
    deployer = accounts[0]
    await deployments.fixture(["all"])
    fundMe = await ethers.getContract("FundMe")
    mockV3Aggregator = await ethers.getContract("MockV3Aggregator")
  })

if you import ethers like this in typescript, getContract function is not available there anymore. What else we can do? @PatrickAlphaC

FundMe fund function unit test throwing error

When doing unit test on fund function of FundMe contract, the test is throwing exception
Seems to be issue with revertedWith function

Test code :

 describe("fund", () => {
        it("fails if you don't send enough ETH", async () => {
            await expect(fundMe.fund()).to.be.revertedWith(
                "You need to spend more ETH"
            )
        })
    })

The test has to be passed with a tick mark but it's throwing following exception:

AssertionError: Expected transaction to be reverted with You need to spend more ETH, but other exception was thrown: Error: VM Exception while processing transaction: reverted with reason string 'Didn't send enough!

Can anyone help with this? Thanks

Solution: Hardhat has been updated (and will not be similar to the video)

For those of you (and me too) that have very little coding experience yet are following along with this great course I'd thought I'd share my pitfall and solution for the following issue:

If you are installing hardhat as per the instructions in the video you may find yourself installing a newer version of Hardhat that does not allow for the "create an advanced sample project" option that is shown in the video. If that should happen to you the following steps can get you back on track to following along with Patrick in the video.

  1. if you have already installed a newer version of hardhat we need to remove that to install the version that Patrick is using (which is version 2.9.3). To do so, type 'yarn remove hardhat' in the terminal. This will remove the latest version (type 'yarn list' in the terminal to check and verify if step 1 worked).

  2. install the correct version of hardhat as used in the video. To do so type 'yarn add --dev [email protected]' in the terminal which will install the older version which Patrick is using. After installation you will find that the option to "create an advanced sample project" is available now.

These two steps have helped me to work around the issues of the newer version.

  1. another issue could be that while running hardhat (via the 'yarn hardhat' command in the terminal) you will not be prompted with a yes/no option to install all the required dependencies (10:04:39 in the video right after the gitignore prompt) but you will be told to do so you yourself. This is really easy to fix as you can copy and paste the message into your terminal. For your convenience here is the command:

yarn add --dev "hardhat@^2.9.3" "@nomiclabs/hardhat-waffle@^2.0.0" "ethereum-waffle@^3.0.0" "chai@^4.2.0" "@nomiclabs/hardhat-ethers@^2.0.0" "ethers@^5.0.0" "@nomiclabs/hardhat-etherscan@^3.0.0" "dotenv@^10.0.0" "eslint@^7.29.0" "eslint-config-prettier@^8.3.0" "eslint-config-standard@^16.0.3" "eslint-plugin-import@^2.23.4" "eslint-plugin-node@^11.1.0" "eslint-plugin-prettier@^3.4.0" "eslint-plugin-promise@^5.1.0" "hardhat-gas-reporter@^1.0.4" "prettier@^2.3.2" "prettier-plugin-solidity@^1.0.0-beta.13" "solhint@^3.3.6" "solidity-coverage@^0.7.16"

If any experts can chime in on any other tips/tricks to help us newbies that would be more than welcome.

From one Patrick (the newbie) to another Patrick (the pro); thanks for sharing your knowledge with us > this may change a lot of lives for the better tips hat to you.

Staging test fails when running yarn hardhat test --network rinkeby

I copied the code from this repo (test/staging/FundMe.staging.test.js) but it doesn't work, this is the error I get:

AssertionError: expected '60000000000000000' to equal '0'

It looks like there is an issue with the endingFundMeBalance variable but I don't know what.
Did someone has the same issue ?

A red underline under the bracket of FundMe__NotOwner()

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;


import "./PriceConverter.sol";
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

error FundMe__NotOwner() [ ### THIS IS WHERE A RED UNDERLINE APPEARS IN MY SOLIDITY FILE];

contract FundMe {
    using PriceConverter for uint256;

    mapping(address => uint256) public addressToAmountFunded;
    address[] public funders;

    // Could we make this constant?  /* hint: no! We should make it immutable! */
    address public /* immutable */ i_owner;
    uint256 public constant MINIMUM_USD = 50 * 10 ** 18;

    AggregatorV3Interface public priceFeed;
    
    constructor(address _priceFeedAddress) {
        priceFeed = AggregatorV3Interface(_priceFeedAddress);
        i_owner = msg.sender;
    }

    function fund() public payable {
        require(msg.value.getConversionRate(priceFeed) >= MINIMUM_USD, "You need to spend more ETH!");
        addressToAmountFunded[msg.sender] += msg.value;
        funders.push(msg.sender);
    }
    
    modifier onlyOwner {
        if (msg.sender != i_owner){ revert FundMe__NotOwner();}
        _;
    }
    
    function withdraw() payable  public {
        for (uint256 funderIndex=0; funderIndex < funders.length; funderIndex++){
            address funder = funders[funderIndex];
            addressToAmountFunded[funder] = 0;
        }
        funders = new address[](0);   
        (bool callSuccess, ) = payable(msg.sender).call{value: address(this).balance}("");
        require(callSuccess, "Call failed");
    }
    
    fallback() external payable {
        fund();
    }

    receive() external payable {
        fund();
    }

}```

 is there anything wrong with the OnlyOwner() ;

Error on storage-fun deploy - Errors encountered in param 1: Invalid value "0x0000000000000000000000000000000000000000000000000000000000000000" supplied to : QUANTITY

Receiving the following error when running the 99-deploy-storage-fun.js ->

----------------------------------------------------
Deploying FunWithStorage and waiting for confirmations...
deploying "FunWithStorage" (tx: 0xf2ce2ca8b8683ca2c6cf0b485fc0881c410149a34ac64c5c6ae9a853175ee4b4)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 227342 gas
Logging storage...
An unexpected error occurred:

Error: ERROR processing /home/user/Desktop/hardhat-fund-me-fcc/deploy/99-deploy-storage-fun.js:
InvalidArgumentsError: Errors encountered in param 1: Invalid value "0x0000000000000000000000000000000000000000000000000000000000000000" supplied to : QUANTITY
    at validateParams (/home/user/Desktop/hardhat-fund-me-fcc/node_modules/hardhat/src/internal/core/jsonrpc/types/input/validation.ts:64:13)

My code is exactly the same not sure if anyone else is running into this issue?

Error: listen EADDRINUSE: address already in use 127.0.0:8545

Hey guys, can anyone help?
When I run yarn hardhat node, I get this error message.

Error: listen EADDRINUSE: address already in use 127.0.0.1:8545
at Server.setupListenHandle [as _listen2] (node:net:1330:16)
at listenInCluster (node:net:1378:12)
at doListen (node:net:1516:7)
at processTicksAndRejections (node:internal/process/task_queues:84:21)
at runNextTicks (node:internal/process/task_queues:65:3)
at listOnTimeout (node:internal/timers:528:9)
at processTimers (node:internal/timers:502:7)
error Command failed with exit code 1.

Error! While testing Fund Function

ERROR:

1) FundMe
       fund
         Fails if you don't send enough ETH:
     AssertionError: Expected transaction to be reverted with You need to spend more ETH, but other exception was thrown: Error: VM Exception while processing transaction: reverted with reason string 'Didn't send enough!

Here's the code i m using to test Fund Function

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

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("sets the aggregator addresses correctly", async function() {
            const response = await fundMe.priceFeed()
            assert.equal(response, mockV3Aggregator.address)
        })
    })

    describe("fund",async function(){
        it("Fails if you don't send enough ETH", async function(){
            await expect(fundMe.fund()).to.be.revertedWith(
                "You need to spend more ETH"
            )
        })
    })
})

Contract wont get verified on etherscan after deployment

So i deployed my contract and it successfully got deployed on etherscan. i checked it on etherscan and it showed up. but the issues is its not getting verified for some reason i have checked the etherscan API key and everything else but no clue! kindly help

here's the code:

 **verify.js:**
const { run } = require("hardhat");

async function verify(contractAddress, args) {
    console.log("Verifying your contract .....")
    try {
        await run("verify:verify", {
            address: contractAddress,
            constructorArguments: args,
        });
        console.log("Verification done");
    } catch (e) {
        if (e.message.toLowerCase() == "already verified") {
            console.log("Already Verified");
        } else {
            console.log(e);
        }
    }
}
module.exports = { verify };

01-deploy-fundme.js:

const { network } = require("hardhat");
const { networkConfig, devChains } = require("../hardhat-helper-config.js");
const { verify } = require("../utils/verify.js");

async function deployFunc(hre) {

    hre.deployments;
    hre.getNamedAccounts;

    const { deploy, log, get } = deployments;
    const { deployer } = await getNamedAccounts();
    const chainId = network.config.chainId;
    let ethUsdPriceFeedAddress;

    if (devChains.includes(network.name)) {
        const ethUsdAggregator = await get("MockV3Aggregator");
        ethUsdPriceFeedAddress = ethUsdAggregator.address;
    } else {
        ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"];
    }


    const fundMe = await deploy("FundMe", {
        contract: "FundMe",
        from: deployer,
        args: [ethUsdPriceFeedAddress],
        log: true,
        waitConfirmations: network.config.blockConfirmations,
    })

    if (!devChains.includes(network.name)) {
        verify(fundMe.address, [ethUsdPriceFeedAddress]);

    }
}

module.exports.default = deployFunc;
module.exports.tags = ["all", "fundme"]

PS: i have checked the function calling is working. i console logged things on the verify.js file above the try block is working but not whats after the try block. so its probably getting stuck inside the try block

Error: cannot find artifact "fundme"

Hi im facing this error when i run the yarn hardhat deploy command:

$ C:\Users\ROSHAN\hardhat-fundme\node_modules\.bin\hardhat deploy
Nothing to compile
Local network detected! Deploying mocks...
deploying "MockV3Aggregator" (tx: 0x2f60bd4cba5dffe33cd22380f4891cfadb7f13aad763bb084e8a1c3336b892f9)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 569635 gas
Mocks deployed!
-----------------------------------------------------------
An unexpected error occurred:

Error: ERROR processing C:\Users\ROSHAN\hardhat-fundme\deploy\01-deploy-fundme.js:
Error: cannot find artifact "fundme"
    at getArtifact (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\DeploymentsManager.ts:207:17)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at runNextTicks (node:internal/process/task_queues:65:3)
    at listOnTimeout (node:internal/timers:526:9)
    at processTimers (node:internal/timers:500:7)
    at getArtifactFromOptions (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\helpers.ts:498:20)
    at getLinkedArtifact (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\helpers.ts:514:38)
    at _deploy (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\helpers.ts:535:54)
    at _deployOne (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\helpers.ts:1004:16)
    at Object.deployFunc [as func] (C:\Users\ROSHAN\hardhat-fundme\deploy\01-deploy-fundme.js:23:5)
    at DeploymentsManager.executeDeployScripts (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1222:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at runNextTicks (node:internal/process/task_queues:65:3)
    at listOnTimeout (node:internal/timers:526:9)
    at processTimers (node:internal/timers:500:7)
    at DeploymentsManager.runDeploy (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1052:5)        
    at SimpleTaskDefinition.action (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\index.ts:438:5)
    at Environment._runTaskDefinition (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat\src\internal\core\runtime-environment.ts:219:14)
    at Environment.run (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat\src\internal\core\runtime-environment.ts:131:14)
    at SimpleTaskDefinition.action (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\index.ts:584:32)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

this is my code:

const { network } = require("hardhat");
const { networkConfig, devChains } = require("../hardhat-helper-config.js");
const { verify } = require("../utils/verify.js");

async function deployFunc(hre) {

    hre.deployments;
    hre.getNamedAccounts;

    const { deploy, log, get } = deployments;
    const { deployer } = await getNamedAccounts();
    const chainId = network.config.chainId;
    let ethUsdPriceFeedAddress;

    if (devChains.includes(network.name)) {
        const ethUsdAggregator = await get("MockV3Aggregator");
        ethUsdPriceFeedAddress = ethUsdAggregator.address;
    } else {
        ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"];
    }


    const fundMe = await deploy("fundme", {
        contract: "fundme",
        from: deployer,
        args: [ethUsdPriceFeedAddress],
        log: true,
        waitConfirmations: network.config.blockConfirmations,
    })

    if (!devChains.includes(network.name)) {
        verify(fundMe.address, [ethUsdPriceFeedAddress]);
    }


}

module.exports.default = deployFunc;
module.exports.tags = ["all", "fundme"]

Can't deploy FundMe, invalid bytecode

This is my deploy script:

const { networkConfig, developmentChains } = require("../helper-hardhat-config")
const { network } = require("hardhat")

module.exports = async ({ getNamedAccounts, deployments }) => {
    const { deploy, log } = deployments
    const { deployer } = await getNamedAccounts()
    const chainId = network.config.chainId

    let ethUsdPriceFeedAddress
    if (developmentChains.includes(network.name)) {
        const ethUsdAggregator = await deployments.get("MockV3Aggregator")
        ethUsdPriceFeedAddress = ethUsdAggregator.address
    } else {
        ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"]
    }

    const fundMe = await deploy("FundMe", {
        from: deployer,
        args: [ethUsdPriceFeedAddress],
        log: true,
    })
    log("_____________________________________________________________")
}

module.exports.tags = ["all", "fundme"]

After typing yarn hardhat deploy Mocks are being deployed and then I get this error:

Nothing to compile
Local network detected! Deploying mocks...
deploying "MockV3Aggregator" (tx: 0x48bdfdd64644a5dd70bcefa793bec388fd55ccc9e6c6b6e4988db8d5cafde888)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 569635 gas
Mocks deployed!
______________________________________________
An unexpected error occurred:

Error: ERROR processing /home/codebind/local_development/hardhat-fund-me/deploy/01-deploy-fund-me.js:
Error: invalid bytecode (argument="bytecode", value="0x60806040526802b5e3af16b188000060005534801561001d57600080fd5b50604051610cd2380380610cd2833981810160405281019061003f919061012a565b33600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050610157565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006100f7826100cc565b9050919050565b610107816100ec565b811461011257600080fd5b50565b600081519050610124816100fe565b92915050565b6000602082840312156101405761013f6100c7565b5b600061014e84828501610115565b91505092915050565b610b6c806101666000396000f3fe6080604052600436106100555760003560e01c80633ccfd60b1461005a5780633e47d6f314610071578063741bef1a146100ae5780638da5cb5b146100d9578063b6a324e014610104578063dc0d3dff1461010e575b600080fd5b34801561006657600080fd5b5061006f61014b565b005b34801561007d57600080fd5b50610098600480360381019061009391906106de565b610397565b6040516100a59190610724565b60405180910390f35b3480156100ba57600080fd5b506100c36103af565b6040516100d0919061079e565b60405180910390f35b3480156100e557600080fd5b506100ee6103d5565b6040516100fb91906107c8565b60405180910390f35b61010c6103fb565b005b34801561011a57600080fd5b506101356004803603810190610130919061080f565b610595565b60405161014291906107c8565b60405180910390f35b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146101db576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101d290610899565b60405180910390fd5b60005b60018054905081101561028757600060018281548110610201576102006108b9565b5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690506000600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555050808061027f90610917565b9150506101de565b50600067ffffffffffffffff8111156102a3576102a2610960565b5b6040519080825280602002602001820160405280156102d15781602001602082028036833780820191505090505b50600190805190602001906102e79291906105d4565b5060003373ffffffffffffffffffffffffffffffffffffffff164760405161030e906109c0565b60006040518083038185875af1925050503d806000811461034b576040519150601f19603f3d011682016040523d82523d6000602084013e610350565b606091505b5050905080610394576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161038b90610a21565b60405180910390fd5b50565b60036020528060005260406000206000915090505481565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000543473__$970d497a1df28a900e3dd97e15a13b1bae$__6321061cc69091600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518363ffffffff1660e01b815260040161045b929190610a5f565b60206040518083038186803b15801561047357600080fd5b505af4158015610487573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104ab9190610a9d565b10156104ec576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104e390610b16565b60405180910390fd5b6001339080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555034600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550565b600181815481106105a557600080fd5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b82805482825590600052602060002090810192821561064d579160200282015b8281111561064c5782518260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550916020019190600101906105f4565b5b50905061065a919061065e565b5090565b5b8082111561067757600081600090555060010161065f565b5090565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006106ab82610680565b9050919050565b6106bb816106a0565b81146106c657600080fd5b50565b6000813590506106d8816106b2565b92915050565b6000602082840312156106f4576106f361067b565b5b6000610702848285016106c9565b91505092915050565b6000819050919050565b61071e8161070b565b82525050565b60006020820190506107396000830184610715565b92915050565b6000819050919050565b600061076461075f61075a84610680565b61073f565b610680565b9050919050565b600061077682610749565b9050919050565b60006107888261076b565b9050919050565b6107988161077d565b82525050565b60006020820190506107b3600083018461078f565b92915050565b6107c2816106a0565b82525050565b60006020820190506107dd60008301846107b9565b92915050565b6107ec8161070b565b81146107f757600080fd5b50565b600081359050610809816107e3565b92915050565b6000602082840312156108255761082461067b565b5b6000610833848285016107fa565b91505092915050565b600082825260208201905092915050565b7f4e6f74206f776e65720000000000000000000000000000000000000000000000600082015250565b600061088360098361083c565b915061088e8261084d565b602082019050919050565b600060208201905081810360008301526108b281610876565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006109228261070b565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415610955576109546108e8565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600081905092915050565b50565b60006109aa60008361098f565b91506109b58261099a565b600082019050919050565b60006109cb8261099d565b9150819050919050565b7f5472616e73616374696f6e206661696c65640000000000000000000000000000600082015250565b6000610a0b60128361083c565b9150610a16826109d5565b602082019050919050565b60006020820190508181036000830152610a3a816109fe565b9050919050565b610a4a8161070b565b82525050565b610a598161077d565b82525050565b6000604082019050610a746000830185610a41565b610a816020830184610a50565b9392505050565b600081519050610a97816107e3565b92915050565b600060208284031215610ab357610ab261067b565b5b6000610ac184828501610a88565b91505092915050565b7f4e65656420746f2073656e64206d6f7265204554480000000000000000000000600082015250565b6000610b0060158361083c565b9150610b0b82610aca565b602082019050919050565b60006020820190508181036000830152610b2f81610af3565b905091905056fea2646970667358221220921d062d0a2af6d171d9c57876aaee50ebf02e5ffc5f17c14beffa75240d0c7364736f6c63430008080033", code=INVALID_ARGUMENT, version=contracts/5.6.2)
    at Logger.makeError (/home/codebind/local_development/hardhat-fund-me/node_modules/@ethersproject/logger/src.ts/index.ts:261:28)
    at Logger.throwError (/home/codebind/local_development/hardhat-fund-me/node_modules/@ethersproject/logger/src.ts/index.ts:273:20)
    at Logger.throwArgumentError (/home/codebind/local_development/hardhat-fund-me/node_modules/@ethersproject/logger/src.ts/index.ts:277:21)
    at new ContractFactory (/home/codebind/local_development/hardhat-fund-me/node_modules/@ethersproject/contracts/src.ts/index.ts:1172:20)
    at _deploy (/home/codebind/local_development/hardhat-fund-me/node_modules/hardhat-deploy/src/helpers.ts:568:17)
    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)
    at _deployOne (/home/codebind/local_development/hardhat-fund-me/node_modules/hardhat-deploy/src/helpers.ts:1004:16)
    at DeploymentsManager.executeDeployScripts (/home/codebind/local_development/hardhat-fund-me/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19)
    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)
    at DeploymentsManager.runDeploy (/home/codebind/local_development/hardhat-fund-me/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
    at SimpleTaskDefinition.action (/home/codebind/local_development/hardhat-fund-me/node_modules/hardhat-deploy/src/index.ts:438:5)
    at Environment._runTaskDefinition (/home/codebind/local_development/hardhat-fund-me/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at Environment.run (/home/codebind/local_development/hardhat-fund-me/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at SimpleTaskDefinition.action (/home/codebind/local_development/hardhat-fund-me/node_modules/hardhat-deploy/src/index.ts:584:32)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Does anyone have the same issue?

Issues with testing and debugging Error: VM Exception while processing transaction: reverted with reason string 'You need to spend more ETH!'

Can someone please help me? I tried debugging it on my own for like 3 hours now and im losing my mind over it now.
I get an error while testing :

  1) FundMe
       fund
         Updates the amount funded data structure:
     Error: VM Exception while processing transaction: reverted with reason string 'You need to spend more ETH!' 

This is my FundMe.test.js:

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

describe("FundMe", async function () {
    let fundMe
    let deployer
    let mockV3Aggregator
    const sendValue = ethers.utils.parseEther("1") // 1 eth
    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)
        })
    })

    describe("fund", async function () {
        it("Fails if you dont send enough ethereum", async function () {
            await expect(fundMe.fund()).to.be.rejectedWith(
                "You need to spend more ETH!"
            )
        })
        it("Updates the amount funded data structure", async function () {
            await fundMe.fund({ value: sendValue })
            const response = await fundMe.getAddressToAmountFunded(deployer)
            assert.equal(response.toString(), sendValue.toString())

This is my FundMe.sol:

// SPDX-License-Identifier: MIT
//Pragma
pragma solidity ^0.8.7;
// Imports
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "./PriceConverter.sol";
// Error Codes
error FundMe__NotOwner();

// Interfaces, Libraries, Contracts

/** @title A contrac for crowd funding
 * @author Aleksander Morawski
 * @notice This contract is a demo of a simple funding contract
 * @dev This implements price feeds as our library
 */
contract FundMe {
    // Type delarations
    using PriceConverter for uint256;

    // State variables
    uint256 public constant MINIMUM_USD = 50 * 10**18;
    mapping(address => uint256) public addressToAmountFunded;
    address[] public funders;
    address public immutable owner;
    AggregatorV3Interface public priceFeed;

    modifier onlyOwner() {
        // require(msg.sender == i_owner, "Sender is not the owner");
        if (msg.sender != owner) revert FundMe__NotOwner();
        _;
    }

    constructor(address priceFeedAddress) {
        owner = msg.sender;
        priceFeed = AggregatorV3Interface(priceFeedAddress);
    }

    /**
     * @notice This funds this contract
     * @dev This implements price feeds as our library
     */
    function fund() public payable {
        require(msg.value.getConversionRate(priceFeed) >= MINIMUM_USD, "You need to spend more ETH!");
        // require(PriceConverter.getConversionRate(msg.value) >= MINIMUM_USD, "You need to spend more ETH!");
        addressToAmountFunded[msg.sender] += msg.value;
        funders.push(msg.sender);
    }

    function withdraw() public onlyOwner {
        // require(msg.sender == owner, "Sender is not an owner!");
        for (
            uint256 funderIndex = 0;
            funderIndex < funders.length;
            funderIndex++
        ) {
            address funder = funders[funderIndex];
            addressToAmountFunded[funder] = 0;
        }
        // reset the array
        funders = new address[](0);

        (bool callSuccess, ) = payable(msg.sender).call{
            value: address(this).balance
        }("");
        require(callSuccess, "Call failed");
    }
}

Error while yarn hardhat deploy --network rinkeby

Hello im following the course and i got stuck. Up to this point ive been problem-solving on my own but here i have hit a wall.
I want to do - yarn hardhat deploy --network rinkeby but i get an error like this :

Nothing to compile
An unexpected error occurred:

Error: ERROR processing C:\Users\Hardhat\hardhat-fund-me\deploy\01-deploy-fund-me.js:16:47
TypeError: Cannot read properties of undefined (reading '4')
    at Object.module.exports [as func]

My deploy script looks like this:

const { network } = require("hardhat")
const { networkConfig, devChains } = require("../helper-hardhat-config")
const {verify} = require("../utils/verify")

module.exports = async ({ getNamedAccounts, deployments }) => {
    const { deploy, log } = deployments
    const { deployer } = await getNamedAccounts()
    const chainId = network.config.chainId

    // const ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"]
    let ethUsdPriceFeedAddress
    if (devChains.includes(network.name)) {
        const ethUsdAggregator = await deployments.get("MockV3Aggregator")
        ethUsdPriceFeedAddress = ethUsdAggregator.address
    } else {
        ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"]
    }

    const args = [ethUsdPriceFeedAddress]
    const fundMe = await deploy("FundMe", {
        from: deployer,
        args: args,
        log: true,
        waitConfirmations: network.config.blockConfirmations || 1,
    })

    if(!devChains.includes(network.name) && process.env.ETHERSCAN_API_KEY){
        await verify(fundMe.address.args)
    }

    log("==================================================")
}
module.exports.tags = ["all", "fundme"]

the only thing that can be "read as 4" in this file - cause this is the error is the chainId pulled from the helper so this is my helper:

const networkCofig = {
    4: {
        name: "rinkeby",
        ethUsdPriceFeed: "0x8A753747A1Fa494EC906cE90E9f37563A8AF630e",
    },
}

const devChains = ["hardhat", "localhost"]
const DECIMALS = 8
const INITIAL_ANSWER = 200000000

module.exports = { networkCofig, devChains, DECIMALS, INITIAL_ANSWER }

Can someone explain what is wrong here?

TypeError: Cannot read properties of undefined (reading 'length')

Hi, im getting this error when i run "yarn hardhat deploy"

this is seems to be in the "00-deploy-mocks.js" file.

TypeError: Cannot read properties of undefined (reading 'length')
    at getFrom (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\helpers.ts:1713:14)  
    at _deploy (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\helpers.ts:533:9)    
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at _deployOne (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\helpers.ts:1004:16)
    at Object.deployFunc [as func] (C:\Users\ROSHAN\hardhat-fundme\deploy\00-deploy-mocks.js:15:9)  
    at DeploymentsManager.executeDeployScripts (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1219:22)
    at DeploymentsManager.runDeploy (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1052:5)
    at SimpleTaskDefinition.action (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\index.ts:438:5)
    at Environment._runTaskDefinition (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat\src\internal\core\runtime-environment.ts:219:14)
    at Environment.run (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat\src\internal\core\runtime-environment.ts:131:14)
    at DeploymentsManager.executeDeployScripts (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1222:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at DeploymentsManager.runDeploy (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1052:5)
    at SimpleTaskDefinition.action (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\index.ts:438:5)
    at Environment._runTaskDefinition (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat\src\internal\core\runtime-environment.ts:219:14)
    at Environment.run (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat\src\internal\core\runtime-environment.ts:131:14)
    at SimpleTaskDefinition.action (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\index.ts:584:32)
    at Environment._runTaskDefinition (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat\src\internal\core\runtime-environment.ts:219:14)
    at Environment.run (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat\src\internal\core\runtime-environment.ts:131:14)
    at SimpleTaskDefinition.action (C:\Users\ROSHAN\hardhat-fundme\node_modules\hardhat-deploy\src\index.ts:669:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Kindly help its been hours!

here's my code:

const { network } = require("hardhat");
const { devChains, _INITIALANSWER, DECIMALS } = require("../hardhat-helper-config.js")


async function deployFunc(hre) {

    hre.getNamedAccounts;
    hre.deployments;

    const { deploy, log } = deployments;
    const { deployer } = await getNamedAccounts();

    if (devChains.includes(network.name)) {
        log("Deploying to development chain..")
        await deploy("MockV3Aggregator", {
            contract: "MockV3Aggregator",
            from: deployer,
            log: true,
            args: [DECIMALS, _INITIALANSWER],
        })
        console.log("Mock deployedd!!")
        console.log("----------------------")

    }
}


module.exports.default = deployFunc;
module.exports.tags = ["all", "mocks"]

PS: i have already added this in my hardhat-config.js file

 NamedAccounts: {
    deployer: {
      default: 0,
    },
  },```

Error: No Contract deployed with name FundMe

Hi im facing this error not sure what im doing wrong
this appears when i run yarn hardhat test

 FundMe
    constructor

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


  0 passing (2s)
  1 failing

  1) FundMe
       "before each" hook for "sets the aggregator addresses correctly":
     Error: No Contract deployed with name FundMe
      at Object.getContract (node_modules\@nomiclabs\hardhat-ethers\src\internal\helpers.ts:447:11)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at runNextTicks (node:internal/process/task_queues:65:3)
      at listOnTimeout (node:internal/timers:526:9)
      at processTimers (node:internal/timers:500:7)
      at Context.<anonymous> (test\unit\Fundme.test.js:16:14)



error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

i don't know why it says no contract deployed even though i have deployed it. and this test code is supposed to get that deployment.

this is the part of code :

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

describe("FundMe", async function () {

  let fundMe;
  let deployer;
  let MockV3Aggregator;
  const sendValue = ethers.utils.parseEther("1")

  beforeEach(async function () {
    deployer = (await getNamedAccounts()).deployer
    await deployments.fixture(["all"]);
    MockV3Aggregator = await ethers.getContract("MockV3Aggregator", deployer)

    fundMe = await ethers.getContract("FundMe", deployer)
  })

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

PS: i have made sure of the naming conventions as well the contract file name and contract name goes by FundMe.sol and FundMe

01-deploy-fund-me gives an error: expected 1 constructor arguments, got 42 [Tutorial Time: 10:59:00]

I am at moment 10:59:00 in the tutorial, I try tu run:

 yarn hardhat deploy --network rinkeby

and it returns me this:

Error: ERROR processing /home/nachoddiaz/Curso32/hardhat-fund-me/deploy/01-deploy-fund-me.js:
Error: expected 1 constructor arguments, got 42

Here is my code:

01-deploy-fund-me.js

const { networkConfig, devChains } = require("../helper-hardhat-config.js")
const { getNamedAccounts, deployments, network } = require("hardhat")
const { verify } = require("../utils/verify.js")

//Podemos resumir las dos lineas anteriores en una sola
module.exports = async ({ getNamedAccounts, deployments }) => {
  const { deploy, log } = deployments
  const { deployer } = await getNamedAccounts()
  const chainId = network.config.chainId

  let ETHUSDPriceAddress //ponemos let para poder actualiarla
  if (devChains.includes(network.name)) {
    //Si estamos en devChain, desplegamos mock
    const ETHUSDAgregator = await deployments.get("MockV3Aggregator")
    ETHUSDPriceAddress = ETHUSDAgregator.address
  } else {
    //Si no estamos en devChain, desplegamos normal
    ETHUSDPriceAddress = networkConfig[chainId]["ETHUSDPrice"]
  }

  const args = ETHUSDPriceAddress

  //cuando trabajemos localhost o en la red hardhat, usaremos un mock
  const fundMe = await deploy("FundMe", {
    from: deployer,
    args: args, // estos argumentos se le pasan al constructor
    log: true,
    waitConfirmations: network.config.blockConfirmations || 1
  })

  if (!devChains.includes(network.name) && process.env.ETHERSCAN_API_KEY) {
    await verify(fundMe.address, args)
  }
  log(
    "----------------------------------------------------------------------------------------------"
  )
}

module.exports.tags = ["all", "fundme"]

hardhat.config.js

require("@nomicfoundation/hardhat-toolbox")
require("hardhat-deploy")
require("dotenv").config()
require("hardhat-gas-reporter")

const Rinkeby_URL = process.env.Rinkeby_RPC_URL
const PRIVATE_KEY_RINKEBY = process.env.Private_KEY
const CMC_API_KEY = process.env.CMCAPI
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY

module.exports = {
  //solidity: "0.8.9",
  networks: {
    rinkeby: {
      url: Rinkeby_URL,
      accounts: [PRIVATE_KEY_RINKEBY],
      chainId: 4,
      blockConfirmations: 6 // esperamos 6 para que a etherscan le de tiempo a indexar nuestra TX
    }
  },
  solidity: {
    compilers: [{ version: "0.8.8" }, { version: "0.6.6" }]
  },
  defaultNetwork: "hardhat",
  gasReporter: {
    enabled: true,
    outputFile: "gas-report.txt",
    noColors: true,
    currency: "USD",
    coinmarketcap: CMC_API_KEY,
    token: "MATIC"
  },
  etherscan: {
    apiKey: process.env.ETHERSCAN_API_KEY
  },
  namedAccounts: {
    deployer: {
      default: 0
    },
    users: {
      default: 0
    }
  }
}

I have spent half an hour trying to solve it, after I have searched on stack exchange but I have not found the answer. I hope you can help me. thanks.

gas-report.txt formatting error

Been following the javascript tutorial (https://www.youtube.com/watch?v=gyMwXuJrbJQ) up to 11:45:21 when my gas-report.txt strangely stopped looking pretty and started looking like this unreadable mess.

·-------------------------|----------------------------|-------------|-----------------------------·
|   �[90mSolc version: 0.8.8�[39m   ·  �[90mOptimizer enabled: false�[39m  ·  �[90mRuns: 200�[39m  ·  �[90mBlock limit: 30000000 gas�[39m  │
··························|····························|·············|······························
|  �[32m�[1mMethods�[22m�[39m                                                                                         │
·············|············|·············|··············|·············|···············|··············
|  �[1mContract�[22m  ·  �[1mMethod�[22m    ·  �[32mMin�[39m        ·  �[32mMax�[39m         ·  �[32mAvg�[39m        ·  �[1m# calls�[22m      ·  �[1musd (avg)�[22m  │
·············|············|·············|··············|·············|···············|··············
|  �[90mFundMe�[39m    ·  fund      ·      �[36m87344�[39m  ·      �[31m104444�[39m  ·      95894  ·           �[90m10�[39m  ·          �[32m�[90m-�[32m�[39m  │
·············|············|·············|··············|·············|···············|··············
|  �[90mFundMe�[39m    ·  withdraw  ·      �[36m35585�[39m  ·       �[31m78293�[39m  ·      56939  ·            �[90m4�[39m  ·          �[32m�[90m-�[32m�[39m  │
·············|············|·············|··············|·············|···············|··············
|  �[32m�[1mDeployments�[22m�[39m            ·                                          ·  �[1m% of limit�[22m   ·             │
··························|·············|··············|·············|···············|··············
|  FundMe                 ·          -  ·           -  ·     874943  ·        �[90m2.9 %�[39m  ·          �[32m�[90m-�[32m�[39m  │
··························|·············|··············|·············|···············|··············
|  MockV3Aggregator       ·          -  ·           -  ·     569635  ·        �[90m1.9 %�[39m  ·          �[32m�[90m-�[32m�[39m  │
·-------------------------|-------------|--------------|-------------|---------------|-------------·

for reference here is the relevant section of hardhat.config.js

gasReporter: {
        enabled: true,
        outputFile: "gas-report.txt",
        nocolors: true,
        currency: "USD",
        // coinmarketcap: COINMARKETCAP_API_KEY,
        token: "MATIC",
    },

TypeError: Cannot read properties of undefined (reading 'ethUsdPriceFeed')

working on hardhat Fund me.... facing an error "TypeError: Cannot read properties of undefined (reading 'ethUsdPriceFeed')".....cant find any solution .......browsed a lot on stack overflow and git ......some of patrick students are facing this same issue but no solution whatsoever ......
error in line: ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"]
file is : 01-deploy-fund-me.js

still got an error

still got an error

mubashirhussain@Mubashirs-MBP harhat Fund me % yarn hardhat deploy --tags all
yarn run v1.22.18
warning package.json: No license field
warning ../../../package.json: No license field
$ '/Users/mubashirhussain/Desktop/course.ss/harhat Fund me/node_modules/.bin/hardhat' deploy --tags all
Nothing to compile
An unexpected error occurred:

Error: ERROR processing skip func of /Users/mubashirhussain/Desktop/course.ss/harhat Fund me/deploy/00-deploy-mocks.js:
ReferenceError: mmodule is not defined
at Object. (/Users/mubashirhussain/Desktop/course.ss/harhat Fund me/helper-hardhat-config.js.js:17:1)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (/Users/mubashirhussain/Desktop/course.ss/harhat Fund me/deploy/00-deploy-mocks.js:2:38)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at DeploymentsManager.executeDeployScripts (/Users/mubashirhussain/Desktop/course.ss/harhat Fund me/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1101:15)
at DeploymentsManager.runDeploy (/Users/mubashirhussain/Desktop/course.ss/harhat Fund me/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1053:16)
at SimpleTaskDefinition.action (/Users/mubashirhussain/Desktop/course.ss/harhat Fund me/node_modules/hardhat-deploy/src/index.ts:409:5)
at Environment._runTaskDefinition (/Users/mubashirhussain/Desktop/course.ss/harhat Fund me/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
at Environment.run (/Users/mubashirhussain/Desktop/course.ss/harhat Fund me/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
at SimpleTaskDefinition.action (/Users/mubashirhussain/Desktop/course.ss/harhat Fund me/node_modules/hardhat-deploy/src/index.ts:555:32)
at Environment._runTaskDefinition (/Users/mubashirhussain/Desktop/course.ss/harhat Fund me/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
at Environment.run (/Users/mubashirhussain/Desktop/course.ss/harhat Fund me/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
at SimpleTaskDefinition.action (/Users/mubashirhussain/Desktop/course.ss/harhat Fund me/node_modules/hardhat-deploy/src/index.ts:640:5)
at Environment._runTaskDefinition (/Users/mubashirhussain/Desktop/course.ss/harhat Fund me/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
mubashirhussain@Mubashirs-MBP harhat Fund me %

Originally posted by @mubashirhussainkhadim in #3 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.