Hardhat deploy script

Hello all, I do appreciate reviewing my deploy script does it set properly or not. thanks in advance

const { ethers } = require('hardhat');

// Deploy function
async function deploy() {
   [account] = await ethers.getSigners();
   deployerAddress = account.address;
   console.log(`Deploying contracts using ${deployerAddress}`);

   //Deploy WETH
   const weth = await ethers.getContractFactory('WETH');
   const wethInstance = await weth.deploy();
   await wethInstance.deployed();

   console.log(`WETH deployed to : ${wethInstance.address}`);

   //Deploy Factory
   const factory = await ethers.getContractFactory('UniswapV2Factory');
   const factoryInstance = await factory.deploy(deployerAddress);
   await factoryInstance.deployed();

   console.log(`Factory deployed to : ${factoryInstance.address}`);

   //Deploy Router passing Factory Address and WETH Address
   const router = await ethers.getContractFactory('UniswapV2Router02');
   const routerInstance = await router.deploy(
   await routerInstance.deployed();

   console.log(`Router V02 deployed to :  ${routerInstance.address}`);

   //Deploy Multicall (needed for Interface)
   const multicall = await ethers.getContractFactory('Multicall');
   const multicallInstance = await multicall.deploy();
   await multicallInstance.deployed();

   console.log(`Multicall deployed to : ${multicallInstance.address}`);

   //Deploy MyToken
   const myToken = await ethers.getContractFactory('MyToken');
   const myTokenInstance = await myToken.deploy();
   await myTokenInstance.deployed();

   console.log(`MyToken deployed to : ${myTokenInstance.address}`);

   //Deploy MasterChef passing MyToken Address
   const masterChef = await ethers.getContractFactory('MasterChef');
   const masterChefInstance = await masterChef.deploy(
   await masterChefInstance.deployed();
   await myToken.transferOwnership(masterChef.address);

   console.log(`MasterChef deployed to :  ${masterChefInstance.address}`);

   //Deploy MyBar passing MyToken Address
   const myBar = await ethers.getContractFactory('MyBar');
   const myBarInstance = await myBar.deploy(
   await myBarInstance.deployed();

   console.log(`MyBar deployed to :  ${myBarInstance.address}`);

   //Deploy MyMaker passing Factory Address, MyBar Address, MyToken Address and WETH Address
   const myMaker = await ethers.getContractFactory('MyMaker');
   const myMakerInstance = await myMaker.deploy(
   await myMakerInstance.deployed();
   await factory.setFeeTo(myMaker.address);

   console.log(`MyMaker deployed to :  ${myMakerInstance.address}`);

   //Deploy Migrator passing Factory Address, MasterChef Address and Uniswap Address
   const migrator = await ethers.getContractFactory('Migrator');
   const migratorInstance = await migrator.deploy(
   await migratorInstance.deployed();

   console.log(`Migrator deployed to :  ${migratorInstance.address}`);

//Deploy MyRoll
   const myRoll = await ethers.getContractFactory('MyRoll');
   const myRollInstance = await myRoll.deploy(
   await myRollInstance.deployed();

   console.log(`MyRoll deployed to : ${myRollInstance.address}`);

   .then(() => process.exit(0))
   .catch((error) => {

It looks fine. But you don't have to import ethers from hardhat. You can delete that line.

Thanks for your suggestion. Please, can you explain in more detail why I need to remove this line.

Since the script will be run by hardhat, ethers will be available to the code in your script without your needing to require it. But in an IDE, it's nice to do the require so that it can code complete and not underline things it doesn't know will be in the global environment at runtime. I personally add that line to all scripts and would NOT recommend removing it.


Thank you so much. so it's required to deploy the contracts in the best manner. my main doubt is do I need to deploy weth contract, if I'll publish it on polygon, or do I need to passing wmatic address to the router contract only, also I do see no need to deploy multicall contract, bc I saw multicall contract addresses already exist on makerdao github for polygon and Mumbai.

Not as such. As 0fatih mentioned, it's not required because it will be globally available to the script when run with hardhat. It's useful to the IDE in its ability to show you problems or make suggestions about its members as you type.

With regard to what contracts you need to deploy, you'll need to research the addresses of your project's external collaborators (WETH, etc) and point to them if your aim is to integrate with them.