PatrickAlphaC / hardhat-fund-me-fcc

82 stars 184 forks source link

Can't deploy mockV3Aggregator #25

Closed Dervoo closed 2 years ago

Dervoo commented 2 years ago

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')
gcedism commented 2 years ago

If you run with the tag --fundme, it will not run the 00-deploy-mocks.js on your local network. This will only work deploying in a testnet

Dervoo commented 2 years ago

Resolved -> network.name problems, fixed. Closing.

jawadgit commented 2 years ago

Hi Dervoo

I am still stuck in this issue.

I am running following command

yarn hardhat deploy

still getting same above error.

please clearly specify where i can change the network

thanks in advance

waiting for your reply

Dervoo commented 2 years ago

In my situation it was only typo for network.name, I would suggest you to check it again at least few times, I checked my code few times and found this typo simply as that ; p

Dervoo commented 2 years ago

Also this one works for me:

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

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 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"]
jawadgit commented 2 years ago

Hi @Dervoo

I am still stuck . I used your code but still same error

I am attaching following code in deploy-fundme.js

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

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 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"] `

I am also attaching helper-hardhat-config.js file code


` const networkConfig = { 31337: { name: "localhost", }, // Price Feed Address, values can be obtained at https://docs.chain.link/docs/reference-contracts // Default one is ETH/USD contract on Kovan 42: { name: "kovan", ethUsdPriceFeed: "0x9326BFA02ADD2366b30bacB125260Af641031331", }, 4: { name: "rinkeby", ethUsdPriceFeed: "0x8A753747A1Fa494EC906cE90E9f37563A8AF630e", }, }

const developmentChains = ["hardhat", "localhost"] const DECIMALS = "8" const INITIAL_PRICE = "200000000000" // 2000

module.exports = { networkConfig, developmentChains, DECIMALS, INITIAL_PRICE } `

im also attaching hardhat.config.js file


` require("@nomiclabs/hardhat-waffle") require("hardhat-gas-reporter") require("@nomiclabs/hardhat-etherscan") require("dotenv").config() require("solidity-coverage") require("hardhat-deploy") // You need to export an object to set up your config // Go to https://hardhat.org/config/ to learn more /**

const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY const KOVAN_RPC_URL = process.env.KOVAN_RPC_URL const RINKEBY_RPC_URL = process.env.RINKEBY_RPC_URL const PRIVATE_KEY = process.env.PRIVATE_KEY const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY

module.exports = { defaultNetwork: "hardhat", networks: { hardhat: { chainId: 31337, // gasPrice: 130000000000, }, kovan: { url: KOVAN_RPC_URL, accounts: [PRIVATE_KEY], chainId: 42, blockConfirmations: 6, gas: 6000000, }, rinkeby: { url: RINKEBY_RPC_URL, accounts: [PRIVATE_KEY], chainId: 4, blockConfirmations: 6, }, }, solidity: { compilers: [ { version: "0.8.8", }, { version: "0.6.6", }, ], }, etherscan: { apiKey: ETHERSCAN_API_KEY, }, gasReporter: { enabled: true, currency: "USD", outputFile: "gas-report.txt", noColors: true, // coinmarketcap: COINMARKETCAP_API_KEY, }, namedAccounts: { deployer: { default: 0, // here this will by default take the first account as deployer 1: 0, // similarly on mainnet it will take the first account as deployer. Note though that depending on how hardhat network are configured, the account 0 on one network can be different than on another }, }, mocha: { timeout: 500000, }, } `

Please tell me where is problem im badly ctsuck i have checked code again and again

jawadgit commented 2 years ago

Hi Bartosz Osińsk and PatrickAlphaC/hardhat-fund-me-fcc

I am attaching my all relevant files please help me out in this scenario as I am stuck in this situation

I tried using your code still im facing errors

please see attached below

deploy-fundme.js const { network } = require("hardhat") const { networkConfig, developmentChains } = 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

let ethUsdPriceFeedAddress
if (chainId == 31337) {
    const ethUsdAggregator = await deployments.get("MockV3Aggregator")
    ethUsdPriceFeedAddress = ethUsdAggregator.address
} else {
    ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"]
}
log("----------------------------------------------------")
log("Deploying FundMe and waiting for confirmations...")
const fundMe = await deploy("FundMe", {
    from: deployer,
    args: [ethUsdPriceFeedAddress],
    log: true,
    // we need to wait if on a live network so we can verify properly
    waitConfirmations: network.config.blockConfirmations || 1
})
log(`FundMe deployed at ${fundMe.address}`)

if (
    !developmentChains.includes(network.name) &&
    process.env.ETHERSCAN_API_KEY
) {
    await verify(fundMe.address, [ethUsdPriceFeedAddress])
}

}

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

deploy-mock.js

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

module.exports = async ({ getNamedAccounts, deployments }) => { const { deploy, log } = deployments const { deployer } = await getNamedAccounts() const chainId = network.config.chainId // If we are on a local development network, we need to deploy mocks! if (developmentChains.includes(network.name)) { 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"]

On Tue, Sep 13, 2022 at 7:39 PM Bartosz Osiński @.***> wrote:

Also this one works for me:

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

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) } log("__")

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

// npx hardhat node -> z tymi ustawieniami pozwoli nam na zdeployowanie kontraktu i mocka lokalnie i tez odpalenia kont `

— Reply to this email directly, view it on GitHub https://github.com/PatrickAlphaC/hardhat-fund-me-fcc/issues/25#issuecomment-1245512626, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACPPGNV6ANM2HIF5RQY3YTLV6CGZ5ANCNFSM52HED6PA . You are receiving this because you commented.Message ID: @.***>

-- و عليكم السلام والرحمة الله وبركاته

Jawwad Nissar +92 - 334 - 904 - 7707 @.*** skype:jawwad.nissar Islamabad