PatrickAlphaC / hardhat-fund-me-fcc

82 stars 182 forks source link

Error trying to deploy mocks. MockV3Aggrigator error. #148

Closed jlgrieve closed 1 year ago

jlgrieve commented 1 year ago

Hello Patrick & Code Camp team,

I've been searching through the repo issues and the internet for a few hours now but keep having errors using hardhat deploy and am not getting anywhere. At this point, I've copy/pasted word-for-word the "00-deploy-mocks.js", "01-deploy-fund-me.js, and "MockV3Aggregator.sol" files.

I'm running into the following error while performing "yarn hardhat deploy --tags mocks" and getting the following response.

yarn run v1.22.15
warning package.json: No license field
$ /home/jlgrieve/hardhat-fund-me-fcc/node_modules/.bin/hardhat deploy --tags mocks
Nothing to compile
Local network detected! Deploying mocks...
An unexpected error occurred:

Error: ERROR processing /home/jlgrieve/hardhat-fund-me-fcc/deploy/00-deploy-mocks.js:
HardhatError: HH701: There are multiple artifacts for contract "MockV3Aggregator", please use a fully qualified name.

Please replace MockV3Aggregator for one of these options wherever you are trying to read its artifact:

@chainlink/contracts/src/v0.6/tests/MockV3Aggregator.sol:MockV3Aggregator
@chainlink/contracts/src/v0.7/tests/MockV3Aggregator.sol:MockV3Aggregator

I try the suggestion in the response above (replace "MockV3Aggregator" in the deploy command for one of the suggested options). Now my "00-deploy-mocks.js" code looks like this (changes in at deploy function):

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 development network, we need to deploy mocks!
    if (chainId == 31337) {
        log("Local network detected! Deploying mocks...")
        await deploy(
            "@chainlink/contracts/src/v0.6/tests/MockV3Aggregator.sol:MockV3Aggregator",
            {
                contract:
                    "@chainlink/contracts/src/v0.6/tests/MockV3Aggregator.sol: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"]

And if I retry "yarn hardhat deploy --tags mocks", the correct console logs appear but with this is the new error:

yarn run v1.22.15
warning package.json: No license field
$ /home/jlgrieve/hardhat-fund-me-fcc/node_modules/.bin/hardhat deploy --tags mocks
Nothing to compile
Local network detected! Deploying mocks...
deploying "@chainlink/contracts/src/v0.6/tests/MockV3Aggregator.sol: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
Please run `npx hardhat console` to interact with the deployed smart contracts!
------------------------------------------------

/home/jlgrieve/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:764
      throw new Error(
            ^
Error: deployment name must not be a path or Fully Qualified Name - for such purposes consider using the "contract" field of deployment options
    at DeploymentsManager.saveDeployment (/home/jlgrieve/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:764:13)
    at Object.save (/home/jlgrieve/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:154:14)
    at /home/jlgrieve/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:384:37
    at _deploy (/home/jlgrieve/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/helpers.ts:650:11)
    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/jlgrieve/hardhat-fund-me-fcc/node_modules/hardhat-deploy/src/helpers.ts:934:16)
    at Object.module.exports [as func] (/home/jlgrieve/hardhat-fund-me-fcc/deploy/00-deploy-mocks.js:12:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

When I do "yarn hardhat deploy" ( to include "01-deploy-fund-me.js) the error is:

Error: No deployment found for: MockV3Aggregator

So I appear to be doing something wrong with the MockV3Aggregator, but nothing I've tried so far works. Any ideas? Sorry for the long question. Just hoping I gave plenty of detail. Any help is appreciated. Thanks

usaamatahir commented 1 year ago

I think you are doing wrong here when you are passing the path in name parameter

await deploy( "@chainlink/contracts/src/v0.6/tests/MockV3Aggregator.sol:MockV3Aggregator", { contract: "@chainlink/contracts/src/v0.6/tests/MockV3Aggregator.sol:MockV3Aggregator", from: deployer, log: true, args: [DECIMALS, INITIAL_PRICE], } )

Try using below Code await deploy( "MockV3Aggregator", { contract: "@chainlink/contracts/src/v0.6/tests/MockV3Aggregator.sol:MockV3Aggregator", from: deployer, log: true, args: [DECIMALS, INITIAL_PRICE], } )

jlgrieve commented 1 year ago

Ahh that worked. Thank you very much!