# deployProxy regularly errors with Invalid deployment when using Infura

**URL:** <https://forum.openzeppelin.com/t/deployproxy-regularly-errors-with-invalid-deployment-when-using-infura/5371>\
**Category:** Upgrades\
**Created:** [January 11, 2021, 5:49pm UTC](https://forum.openzeppelin.com/t/deployproxy-regularly-errors-with-invalid-deployment-when-using-infura/5371 "2021-01-11T17:49:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gravityblast](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/gravityblast/32/4046_2.png) [@gravityblast](https://forum.openzeppelin.com/u/gravityblast)\
**Post date:** [January 11, 2021, 5:49pm UTC](https://forum.openzeppelin.com/t/deployproxy-regularly-errors-with-invalid-deployment-when-using-infura/5371/1 "2021-01-11T17:49:57Z")

</div>

Hey everyone,  
I often have this error while deploying an upgradeable contract via Infura:

`Invalid deployment with address 0x... and 0x...`

**💻 Environment**

hardhat 2.0.6:  
@nomiclabs/hardhat-ethers 2.0.1  
@openzeppelin/contracts-upgradeable@ 3.3.0  
@openzeppelin/hardhat-upgrades 1.4.3

**📝Details**

The tx is actually sent and mined correctly but when the `waitAndValidateDeployment` function of the `@openzeppelin/upgrades-core` package checks the tx with `getTransactionByHash`, the provider returns `null`.  
If I put an `await sleep(5000)` before that, I don’t have problems, so I guess the infura node I’m hitting doesn’t know about that tx yet.

I guess in that `while` loop we could retry `N` times even in this case, but I’m asking because I’m not sure it would be the right place to do it.

Does this happen to someone else?

**🔢 Code to reproduce**

```auto
    const myContract = await ethers.getContractFactory("MyContract", signer);
    const proxy = await upgrades.deployProxy(myContract, [args]);
    await proxy.deployed();

```

---

<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:** [January 12, 2021, 4:23am UTC](https://forum.openzeppelin.com/t/deployproxy-regularly-errors-with-invalid-deployment-when-using-infura/5371/2 "2021-01-12T04:23:40Z")

</div>

Hi @gravityblast,

Welcome to the community 👋

I am sorry that you are having this issue.

What network are you deploying to? Have you tried using a different provider (e.g. Alchemy: [https://docs.openzeppelin.com/learn/connecting-to-public-test-networks](https://docs.openzeppelin.com/learn/connecting-to-public-test-networks))

I just tried [OpenZeppelin Upgrades: Step by Step Tutorial for Hardhat](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580) using Infura to Rinkeby with no issues.

```auto
$ npx hardhat run --network rinkeby scripts/deploy.js
Compiling 1 file with 0.7.3
Compilation finished successfully
Deploying Box...
Box deployed to: 0xfD1dafA50bC4362a792531285b047C14D75c5D5b

```

## deploy.js

```auto
// scripts/deploy.js
async function main() {
    const Box = await ethers.getContractFactory("Box");
    console.log("Deploying Box...");
    const box = await upgrades.deployProxy(Box, [42], { initializer: 'store' });
    console.log("Box deployed to:", box.address);
  }
  
  main()
    .then(() => process.exit(0))
    .catch(error => {
      console.error(error);
      process.exit(1);
    });

```

---

<div class="post-metadata">

**Author:** ![gravityblast](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/gravityblast/32/4046_2.png) [@gravityblast](https://forum.openzeppelin.com/u/gravityblast)\
**Post date:** [January 12, 2021, 8:53am UTC](https://forum.openzeppelin.com/t/deployproxy-regularly-errors-with-invalid-deployment-when-using-infura/5371/3 "2021-01-12T08:53:12Z")

</div>

thank you @abcoathup ! It’s both with kovan and mainnet.  
Yes with alchemy it seems to always work, but with infura it’s always the same so I was wondering if that change could be good to manage this problem.  
If that makes sense I could open a PR.

---

<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:** [January 13, 2021, 3:17am UTC](https://forum.openzeppelin.com/t/deployproxy-regularly-errors-with-invalid-deployment-when-using-infura/5371/4 "2021-01-13T03:17:39Z")

</div>

HI @gravityblast,

After a few tries I managed to reproduce on Kovan using Infura.

I’ll check with the development team what would be the best work around.

## Cleanup

```auto
$ rm -rf artifacts/
$ rm -rf .openzeppelin/

```

## Deploy

```auto
$ npx hardhat run --network kovan scripts/deploy.js
Compiling 1 file with 0.7.3
Compilation finished successfully
Deploying Box...
{ Error: Invalid deployment with address 0x03EB1e2956AA03a086a3511BCDaeFAcB1e438086 and txHash 0x0d18b824ea4137fce5386fb50307732987d39bdd870ecf0e836f5012be22d512
    at Object.waitAndValidateDeployment (/home/abcoathup/projects/forum/gravityblast/node_modules/@openzeppelin/upgrades-core/src/deployment.ts:66:15)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  deployment:
   { address: '0x03EB1e2956AA03a086a3511BCDaeFAcB1e438086',
     txHash:
      '0x0d18b824ea4137fce5386fb50307732987d39bdd870ecf0e836f5012be22d512',
     layout: { storage: [Array], types: [Object] } } }

```

---

<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:** [January 13, 2021, 10:28pm UTC](https://forum.openzeppelin.com/t/deployproxy-regularly-errors-with-invalid-deployment-when-using-infura/5371/5 "2021-01-13T22:28:19Z")

</div>

Hi @gravityblast.

> [@gravityblast](#):
>
> I guess the infura node I’m hitting doesn’t know about that tx yet.

Yes, this is very likely the reason.

I think we can safely remove the exception we raise, and continue retrying until we see something or time out.

If you would like to provide a PR, if I'm not mistaken we have to replace the following

> <https://github.com/OpenZeppelin/openzeppelin-upgrades/blob/6ffc421f0db0c8ab5dad19b978e50f59aa6ef1b9/packages/core/src/deployment.ts#L65-L67>

with something like

```typescript
if (tx === null) {
  continue;
}

```

---

<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:** [January 14, 2021, 11:28pm UTC](https://forum.openzeppelin.com/t/deployproxy-regularly-errors-with-invalid-deployment-when-using-infura/5371/6 "2021-01-14T23:28:52Z")

</div>

I should have fixed this in [https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/282](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/282).

---

<div class="post-metadata">

**Author:** ![gravityblast](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/gravityblast/32/4046_2.png) [@gravityblast](https://forum.openzeppelin.com/u/gravityblast)\
**Post date:** [January 15, 2021, 11:26am UTC](https://forum.openzeppelin.com/t/deployproxy-regularly-errors-with-invalid-deployment-when-using-infura/5371/7 "2021-01-15T11:26:44Z")

</div>

great!! thank you @frangio !

---

<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:** [January 18, 2021, 12:01am UTC](https://forum.openzeppelin.com/t/deployproxy-regularly-errors-with-invalid-deployment-when-using-infura/5371/8 "2021-01-18T00:01:41Z")

</div>

HI @frangio & @gravityblast,

It looks resolved; I haven’t been able to reproduce since upgrading to the latest version.
