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

**URL:** <https://forum.openzeppelin.com/t/with-hardhat-deploy-how-do-i-access-a-contract-instance-previously-deployed-with-upgrades-plugin/28644>\
**Category:** Upgrades\
**Tags:** proxies, upgrades, upgrades-plugins, hardhat\
**Created:** [May 11, 2022, 9:46pm UTC](https://forum.openzeppelin.com/t/with-hardhat-deploy-how-do-i-access-a-contract-instance-previously-deployed-with-upgrades-plugin/28644 "2022-05-11T21:46:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![darkWingDuckCurry](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/darkwingduckcurry/32/10606_2.png) [@darkWingDuckCurry](https://forum.openzeppelin.com/u/darkWingDuckCurry)\
**Post date:** [May 11, 2022, 9:46pm UTC](https://forum.openzeppelin.com/t/with-hardhat-deploy-how-do-i-access-a-contract-instance-previously-deployed-with-upgrades-plugin/28644/1 "2022-05-11T21:46:49Z")

</div>

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

_Context:_  
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.

🛰 Thanks in advance. 🛰

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [May 12, 2022, 4:06am UTC](https://forum.openzeppelin.com/t/with-hardhat-deploy-how-do-i-access-a-contract-instance-previously-deployed-with-upgrades-plugin/28644/2 "2022-05-12T04:06:16Z")

</div>

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

```auto
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](https://github.com/wighawag/hardhat-deploy/issues/242#issuecomment-998790266).

---

<div class="post-metadata">

**Author:** ![darkWingDuckCurry](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/darkwingduckcurry/32/10606_2.png) [@darkWingDuckCurry](https://forum.openzeppelin.com/u/darkWingDuckCurry)\
**Post date:** [May 12, 2022, 8:15pm UTC](https://forum.openzeppelin.com/t/with-hardhat-deploy-how-do-i-access-a-contract-instance-previously-deployed-with-upgrades-plugin/28644/3 "2022-05-12T20:15:23Z")

</div>

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:

```auto
  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:

```auto
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!
