'How to deploy multiple smart contracts using hardhat-deploy
I have two smart contracts that I want to deploy. I want to deploy the first one, then pass the address of the first into the constructor of the second one. I am new to hardhat-deploy and keep getting caught up with this.
Thanks!
Solution 1:[1]
First create file "scripts/deploy.js".
const { ethers } = require("hardhat");
async function main() {
const [deployer] = await ethers.getSigners();
console.log('Deploying contracts with the account: ' + deployer.address);
// Deploy First
const First = await ethers.getContractFactory('FirstContract');
const first = await First.deploy();
// Deploy Second
const Second = await ethers.getContractFactory('SecondContract');
const second = await Second.deploy(first.address);
console.log( "First: " + first.address );
console.log( "Second: " + second.address );
}
main()
.then(() => process.exit())
.catch(error => {
console.error(error);
process.exit(1);
})
Then run this command.
npx hardhat run scripts/deploy.js --network ropsten
Solution 2:[2]
The original question specifically refers to the hardhat-deploy
NPM package (i.e. the community plugin for hardhat tooling). On that basis the answer provided is not directly correct.
hardhat-deploy
's documentation is extensive and thorough. The portion relevant to the deployment of (multiple) contracts is here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Yuri Hovakimyan |
Solution 2 | ZeusLawyer |