Modifying an existing module
It’s possible to make changes to modules after having deployed them.
For example, if we wanted to add a new Rocket contract instance to the module we deployed in the Quick Start guide, this is what we would do:
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
export default buildModule("Apollo", (m) => { const apollo = m.contract("Rocket", ["Saturn V"]);
m.call(apollo, "launch", []);
const artemis = m.contract("Rocket", ["Artemis 2"], { id: "artemis" });
m.call(artemis, "launch", []);
return { apollo, artemis };});Then run it again. Hardhat Ignition will continue from where it left off, and execute the new parts of the module.
npx hardhat ignition deploy ignition/modules/Apollo.ts --network localhostpnpm hardhat ignition deploy ignition/modules/Apollo.ts --network localhostyarn hardhat ignition deploy ignition/modules/Apollo.ts --network localhostThis is what the output would look like:
Batch #1 Executed Apollo#artemis
Batch #2 Executed Apollo#Apollo.artemis.launch
[ Apollo ] successfully deployed 🚀
Deployed Addresses
Apollo#Rocket - 0x5fbdb2315678afecb367f032d93f642f64180aa3Apollo#artemis - 0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0We can see two new batches that execute the new parts of the module, while keeping the previous already deployed parts intact.
Incompatible modifications
Section titled “Incompatible modifications”There are certain modifications one can make to a Future definition that would make the new version incompatible with the previous one if the previous one has already been partially or completely executed. This would lead to Hardhat Ignition being unable to continue your deployment from where it was left off. Read the Reconciliation guide to learn more about this.
Clearing an existing deployment with reset
Section titled “Clearing an existing deployment with reset”In the above case, or if you simply want to start over, you can use the --reset option to clear the previous deployment and start from scratch:
npx hardhat ignition deploy ignition/modules/Apollo.ts --network localhost --resetpnpm hardhat ignition deploy ignition/modules/Apollo.ts --network localhost --resetyarn hardhat ignition deploy ignition/modules/Apollo.ts --network localhost --reset