Closed Nikhil8400 closed 9 months ago
//This is my deploy-mocks file
const {network, deployments} = require("hardhat") const {developmentChains, DECIMALS, INITIAL_ANSWER} = require("../helper-hardhat-config.js")
module.exports = async ({ getNamedAccounts, deployment})=>{ const {deploy, log} = deployments const{deployer} = await getNamedAccounts() const chainId = network.config.chainId
if(chainId == 31337){
log("Local network detected! Deploying mocks....")
await deploy("MockV3Aggregator", {
contract:"MockV3Aggregator",
from: deployer,
log:true,
args:[DECIMALS,INITIAL_ANSWER] //we have to pass constructor parameter for mockV3Aggregator
//decimal parameter is going to equal to this decimal function... and the _initial answer parameter tells with what does price feed starting with
//Decimal should be placed 1st then place initial_answer accoding the constructor for MockV3Aggregator we can go and check in node modules files
})
log("Mocks deployed!")
log("___________________________________________________")
}
}
module.exports.tags = ["all","mocks"]
Try using this code. You will need to create a development chains array in your heper-hardhat-config with ["hardhat","localhost"] for the if statement
//Contract that we can use to deploy a fake price feed to a blockchain
const { network } = require("hardhat")
const { networkConfig } = require("../helper-hardhat-config")
const {
developmentChains,
DECIMALS,
INITIAL_ANSWER,
} = require("../helper-hardhat-config")
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, //is deploying, what transaction is doing and where it is deployed with how much gas
args: [DECIMALS, INITIAL_ANSWER],
})
log("Mocks deployed")
log("-----------------------------------------------------------")
}
//We don't want to deploy this mock contract to a test net that actually has price feed
}
module.exports.tags = ["all", "mocks"]
i have used await with get named accounts