Skip to content

Commit

Permalink
Extrct deployment transaction from upgraded contract
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jagodarybacka committed Jan 23, 2024
1 parent b5fb923 commit 5e1fda0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/upgrades.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import "@openzeppelin/hardhat-upgrades"

import type { Contract, ContractFactory } from "ethers"
import type {
Contract,
ContractFactory,
ContractTransactionResponse,
} from "ethers"
import type {
Artifact,
FactoryOptions,
Expand Down Expand Up @@ -149,7 +153,11 @@ async function upgradeProxy<T extends Contract>(
opts?.proxyOpts
)) as T

const deploymentTransaction = newContractInstance.deploymentTransaction()
// This is a workaround to get the deployment transaction. The upgradeProxy attaches
// the deployment transaction to the field under a different name than ethers
// contract.deploymentTransaction() function expects.
const deploymentTransaction =
newContractInstance.deployTransaction as unknown as ContractTransactionResponse

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

0 comments on commit 5e1fda0

Please sign in to comment.