gm guys, I have a question about the InheritanceSubmission on the basecamp contract: I performed the following steps to deploy my contracts using Hardhat's Ignition:
- I deployed the Salesperson and EngineerManager contracts in the same ignition and recorded both contract numbers.
- I created another ignition module to deploy the InheritanceSubmission, passing the addresses of the previously deployed Salesperson and EngineerManager contracts.
- I executed the Hardhat ignition command to deploy the InheritanceSubmission contract, but…
Although my InheritanceSubmissionModule only deploys the InheritanceSubmissionModule, it also redeployed the Salesperson and EngineerManager contracts. So, I'm wondering if there's a way to deploy all three contracts in the same ignition module. Ideally, after deploying the Salesperson and EngineerManager contracts, I could get the contract numbers of both and pass these numbers as parameters to the InheritanceSubmission. Alternatively, I want to know how to prevent Hardhat from redeploying my Salesperson and EngineerManager contracts when I try to deploy only the InheritanceSubmission contract.
Here is the link of the excercise in case you want to check
Edit: add ignition scripts:
salesperson and engineermanager contracts:
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
const salesPersonHourlyRate = 20;
const salesPersonIdNumber = 55555;
const salesPersonManagerId = 12345;
const emAnnualSalary = 200000;
const emIdNumber = 54321;
const emManagerId = 11111;
const InheritanceModule = buildModule("InheritanceModule", (m) => {
const hourlyRate = m.getParameter("hourlyRate", salesPersonHourlyRate);
const managerId = m.getParameter("managerId", salesPersonManagerId);
const idNumber = m.getParameter("IdNumber", salesPersonIdNumber);
const annualSalary = m.getParameter("annualSalary", emAnnualSalary);
const idNumberEm = m.getParameter("IdNumber", emIdNumber);
const managerIdEm = m.getParameter("managerId", emManagerId);
const salesPerson = m.contract("Salesperson", [
idNumber,
managerId,
hourlyRate,
]);
const engineerManager = m.contract("EngineeringManager", [
idNumberEm,
managerIdEm,
annualSalary,
]);
return { salesPerson, engineerManager };
});
export default InheritanceModule;
InheritanceSubmitionModule Contract
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
const salespersonContract = "0x7E969c14eeCcB542d11f0cAA533dE30A097d82eC";
const enginnerManagerContract = "0xFCb006323675EE6fAfd3f74934DbB6C8E856a883";
const InheritanceSubmitionModule = buildModule(
"InheritanceSubmitionModule",
(m) => {
const salespersonAddress = m.getParameter(
"salesperson",
salespersonContract
);
const engineerManagerAddress = m.getParameter(
"engineerManager",
enginnerManagerContract
);
const inheritanceSubmition = m.contract("InheritanceSubmission", [
salespersonAddress,
engineerManagerAddress,
]);
}
);
export default InheritanceSubmitionModule;
Best Answer
Hardhat Ignition doesn't seem to provide a way (yet) to retrieve the contract addresses directly after deployment, particularly because it creates
Future
artifacts corresponding to the contracts during deployment.However, with a general Hardhat Script, you can achieve the same easily.
You can just create a
script
folder, and createdeploy.js
file inside the same. Then, you can simply copy-paste this code in thedeploy.js
file:Then, execute the script using this command:
P.S. You can change the network from
hardhat
to any other network as specified in yourhardhat.config.js
.