I have seen two methods of how Solidity smart contract get deployed on Hardhat. I would generalize them as follows:
METHOD 1
const hre = require("hardhat");
async function main() {
const [deployer] = await ethers.getSigners();
const contractFactory = await hre.ethers.getContractFactory("someContractName");
const contractInstance = await contractFactory.deploy();
await contractInstance.deployed();
...
...
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
METHOD 2
module.exports = async ({ getNamedAccounts, deployments, getChainId }) => {
const { deploy, log } = deployments
const { deployer } = await getNamedAccounts()
const chainId = await getChainId()
const contractInstance = await deploy('myContract', {from: deployer,
log: true,
});
............
............
}
While they both result in contract deployment, I am unable to understand how they both achieve the same results. how are these two deployment methods related, if at all? ( I would like to know what's going on under the hood )