5

I am running hardhat. How do I ensure the contract below is always deployed to a specific address on my localhost dev chain, say: 0x5FbDB2315678afecb367f032d93F642f64180aa3:

  const Factory = await hre.ethers.getContractFactory("FactoryContract");
  const factory = await Factory.deploy(owner.address);

await factory.deployed();

The reason I want to do this is I want to run subsequent scripts which interact with this contract and I don't want to have to lookup the factory contract address every time I restart my dev chain.

David Simic
  • 182
  • 5
  • the address is deterministic, if you either use create2, or know how many transactions have occured since the deployment.
  • What do you mean you don't want to have to look up the factory contract? All you have to do is save the artifact after deploying and then calling it using the get function
  • – johnny 5 Jan 19 '23 at 15:43
  • It is not deterministic in my experience using the above code snippet - I get a different address each time I restart the block chain and deploy for the first time. – David Simic Jan 19 '23 at 17:08
  • Create2 should make it deterministic on local (assuming no transactions are made to the account in between testing) – johnny 5 Jan 19 '23 at 17:27
  • Thanks, but how do I use Create2 in this script? Can't find documentation. Unless you are referring to me manually deploying first my own deployer contract which implements create2...? – David Simic Jan 20 '23 at 17:10
  • Why do you even need create2, this still doesn't make sense to me, why arent you just storing the contract in the artifacts, and then call (await get("FactoryContract")).address – johnny 5 Jan 20 '23 at 17:20