With hardhat-deploy, how do I access a contract instance previously deployed with upgrades plugin?

Is there an equivalent method to
that gives me access to the deployment contract that is returned from:
await exampleContract.deployed()
which was previously deployed with OpenZeppelin upgrades?
const ExContract = await exampleContract.deployProxy();
const exContract = await exampleContract.deployed();

I've deployed a contract using the hardhat deploy plugin in conjunction with
Openzepplin's upgrades.
In essence I've populated my deploy folder with a sequence of 4 files (01-04) each deploying different contracts.
Inside of each deploymentFunction, I'm deploying the upgradable contract with:
const GovToken = await ethers.getContractFactory("GovToken");
const govToken = await upgrades.deployProxy(GovToken, { kind: "uups" });
await govToKen.deployed();
I've deployed these contracts to a local node. This all works fine.
Where I'm hitting a wall is:
I'm attempting to invoke a script, post deployment, that needs access to the previously deployed contract instance.
How can I get access to these now deployed contracts in another script?

In the past, before using the upgrades plugin, I would use
from hardhat deploy: hre.deployments.get("ExampleContract")
or from ethers : ether.getContract("ExampleContract")

I've scoured the internet and openZepplin's upgrades API as well as upgradesCore in my node module but cant see to find anything.

:satellite: Thanks in advance. :satellite:

Are you able to retrieve the address of the previously deployed proxy? If so, you could just do:

const GovToken = await ethers.getContractFactory("GovToken");
const govToken = GovToken.attach(greeter.address);

Or if you are looking to save the address to your deployments in the first place, you could see the example in this comment for hardhat-deploy.

1 Like

In the event that anyone else has this problem, I used the save() and get() methods made avail by hardhat deploy, and the getContractAt() method via hardhat ethers:

  const timeLock = await upgrades.deployProxy(TimeLock as ContractFactory, ARGS, {
    kind: "uups",
  await timeLock.deployed();

 await save("TimeLock", {
    address: timeLock.address,
    ...(artifact as ExtendedArtifact),

followed by, in another script:

const [timeLock, govToken] = await Promise.all([get("TimeLock"), get("GovToken")]);
const TimeLock = await ethers.getContractAt("TimeLock", timeLock.address);
const GovToken = await ethers.getContractAt("GovToken", govToken.address);

@ericglau You are a gentleman and a scholar.

Thank you kind human!

1 Like