# Invalid deployment when forking network on Hardhat

**URL:** <https://forum.openzeppelin.com/t/invalid-deployment-when-forking-network-on-hardhat/4672>\
**Category:** Upgrades\
**Created:** [November 19, 2020, 12:53pm UTC](https://forum.openzeppelin.com/t/invalid-deployment-when-forking-network-on-hardhat/4672 "2020-11-19T12:53:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![drbullock](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/drbullock/32/3587_2.png) [@drbullock](https://forum.openzeppelin.com/u/drbullock)\
**Post date:** [November 19, 2020, 12:53pm UTC](https://forum.openzeppelin.com/t/invalid-deployment-when-forking-network-on-hardhat/4672/1 "2020-11-19T12:53:02Z")

</div>

**💻 Environment**  
hardhat: 2.0.3  
@openzeppelin/upgrades-core: 1.3.1  
@openzeppelin/hardhat-upgrades: 1.3.0

**📝Details**  
I am using OpenZeppelin Upgrades with Hardhat Forking Network, but when I try to Test/Deploy I keep getting this error.

`Error: Invalid deployment with address 0xe7f1725E7734CE288F...... and txHash 0x4ebb5224a87d6875669d1bb6126d..................`

Sometimes, one of the contracts gets deployed successfully, and then it stuck in one of the other ones.

I traced the @openzeppelin\upgrades-core and the problem stands here: [https://github.com/OpenZeppelin/openzeppelin-upgrades/blob/bd53a81938d2a9781d9dac30f477d95bd58298e0/packages/core/src/deployment.ts#L35](https://github.com/OpenZeppelin/openzeppelin-upgrades/blob/bd53a81938d2a9781d9dac30f477d95bd58298e0/packages/core/src/deployment.ts#L35)

Since is a forked network, `chainId = 1` and it markes the env as production. Is there any way to ignore this issue?

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [November 20, 2020, 7:08am UTC](https://forum.openzeppelin.com/t/invalid-deployment-when-forking-network-on-hardhat/4672/2 "2020-11-20T07:08:35Z")

</div>

Hi @drbullock,

I am sorry that you had this issue. I was able to reproduce and have created an issue: [https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/233](https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/233)

---

<div class="post-metadata">

**Author:** ![frangio](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/frangio/32/15251_2.png) [@frangio](https://forum.openzeppelin.com/u/frangio)\
**Post date:** [November 20, 2020, 2:51pm UTC](https://forum.openzeppelin.com/t/invalid-deployment-when-forking-network-on-hardhat/4672/3 "2020-11-20T14:51:21Z")

</div>

This is happening because the Upgrades plugin stores the network state according to the chain id, but since you’re working with a fork the state doesn’t really reflect the network’s, and subsequent runs realize this and fail.

One workaround could be to customize the chain id. This is possible on Ganache but doesn’t seem possible in Hardhat Network. I’ve opened an issue:

> <https://github.com/nomiclabs/hardhat/issues/1042>
>
> I tried the following configuration but the chain id is still 1:
> hardhat: {
> chainId: 31337,
> forking: {
> url: \`https://cloudflare-eth.com/\`,
> },
> ...

We will see what we can do to fix this out of the box in the Upgrades plugin.

---

<div class="post-metadata">

**Author:** ![drbullock](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/drbullock/32/3587_2.png) [@drbullock](https://forum.openzeppelin.com/u/drbullock)\
**Post date:** [November 23, 2020, 3:35pm UTC](https://forum.openzeppelin.com/t/invalid-deployment-when-forking-network-on-hardhat/4672/4 "2020-11-23T15:35:22Z")

</div>

In this case, I will try to make the tests with ganache. Thank you!

---

<div class="post-metadata">

**Author:** ![astrovicis](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/astrovicis/32/4974_2.png) [@astrovicis](https://forum.openzeppelin.com/u/astrovicis)\
**Post date:** [April 8, 2021, 7:02pm UTC](https://forum.openzeppelin.com/t/invalid-deployment-when-forking-network-on-hardhat/4672/5 "2021-04-08T19:02:46Z")

</div>

Bump. Separately ran into this issue and came across this thread.

---

<div class="post-metadata">

**Author:** ![Skyge](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skyge/32/343_2.png) [@Skyge](https://forum.openzeppelin.com/u/Skyge)\
**Post date:** [April 9, 2021, 1:05am UTC](https://forum.openzeppelin.com/t/invalid-deployment-when-forking-network-on-hardhat/4672/6 "2021-04-09T01:05:19Z")

</div>

It seems like they have fixed this error, so I think you can use the latest version to have a try.
