Skip to content

Commit 5e1fda0

Browse files
committed
Extrct deployment transaction from upgraded contract
After proxy contract is upgraded we had a problem with extracting deployment transaction via `contract.deploymentTransaction()` from ethers. It was happening because OpenZeppelin's `upgradeProxy` was replacing deployment tx on the proxy contract but the field was different than what ethers function expected. Let's make it work by directly using the field that `upgradeProxy` adds on the contact's object.
1 parent b5fb923 commit 5e1fda0

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/upgrades.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import "@openzeppelin/hardhat-upgrades"
22

3-
import type { Contract, ContractFactory } from "ethers"
3+
import type {
4+
Contract,
5+
ContractFactory,
6+
ContractTransactionResponse,
7+
} from "ethers"
48
import type {
59
Artifact,
610
FactoryOptions,
@@ -149,7 +153,11 @@ async function upgradeProxy<T extends Contract>(
149153
opts?.proxyOpts
150154
)) as T
151155

152-
const deploymentTransaction = newContractInstance.deploymentTransaction()
156+
// This is a workaround to get the deployment transaction. The upgradeProxy attaches
157+
// the deployment transaction to the field under a different name than ethers
158+
// contract.deploymentTransaction() function expects.
159+
const deploymentTransaction =
160+
newContractInstance.deployTransaction as unknown as ContractTransactionResponse
153161

154162
// Let the transaction propagate across the ethereum nodes. This is mostly to
155163
// wait for all Alchemy nodes to catch up their state.

0 commit comments

Comments
 (0)