Files
hardhat-simple-storage/deploy/01-deploy-fund-me.js
T

79 lines
2.5 KiB
JavaScript

// import
const { ethers, run, network } = require("hardhat");
const {
networkConfig,
developmentChains,
} = require("../helper-hardhat-config");
/* Above same as:
const helperConfig = require("../helper-hardhat-config");
const networkConfig = helperConfig.networkConfig;
*/
const { verify } = require("../utils/verify");
/*
// main function that auto run via hardhat deploy
function deployFunc() {
const { getNamedAccounts, deployments } = hre; // Hardhat runtime environment
// Same as hre.getNamedAccounts & hre.deployments
console.log("Hello World!");
}
module.exports.default = deployFunc;
*/
/*
module.exports = async () => {
let contractAddress = "0x3a827C119e1D746bb3C7bcbbf95c55246C8CcBdd";
let priceFeedAddress = "0x694AA1769357215DE4FAC081bf1f309aDC325306";
await verify(contractAddress, [priceFeedAddress]);
};
*/
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts(); // Take from hardhat.config.js namedAccounts
const chainId = network.config.chainId;
let ethUsdPriceFeedAddress;
/*
31337 - Local Hardhat Network
5777 - Local Ganache Network
11155111 - Sepolia Testnet
When going for localhost / hardhat network we want to use a mock
*/
switch (chainId) {
case 31337:
ethUsdAggregator = await deployments.get("MockV3Aggregator");
ethUsdPriceFeedAddress = ethUsdAggregator.address;
break;
case 5777:
ethUsdAggregator = await deployments.get("MockV3Aggregator");
ethUsdPriceFeedAddress = ethUsdAggregator.address;
break;
default:
ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"];
}
log("----------------------------------------------------");
log("Deploying FundMe Contract and waiting for confirmations...");
const argsPriceFeed = [ethUsdPriceFeedAddress];
const fundMe = await deploy("FundMe", {
from: deployer,
args: argsPriceFeed,
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 on testnet, then verify smart contract
if (
!developmentChains.includes(network.name) &&
process.env.ETHERSCAN_API_KEY
) {
// Verify Code
await verify(fundMe.address, argsPriceFeed);
}
};
module.exports.tags = ["all", "fundme"];