# Specifying an initializer to be called in proposeUpgrade

**URL:** <https://forum.openzeppelin.com/t/specifying-an-initializer-to-be-called-in-proposeupgrade/35985>\
**Category:** Upgrades\
**Tags:** upgrades, upgrades-plugins\
**Created:** [May 3, 2023, 5:40pm UTC](https://forum.openzeppelin.com/t/specifying-an-initializer-to-be-called-in-proposeupgrade/35985 "2023-05-03T17:40:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hmm](https://avatars.discourse-cdn.com/v4/letter/h/eb9ed0/32.png) [@hmm](https://forum.openzeppelin.com/u/hmm)\
**Post date:** [May 3, 2023, 5:40pm UTC](https://forum.openzeppelin.com/t/specifying-an-initializer-to-be-called-in-proposeupgrade/35985/1 "2023-05-03T17:40:44Z")

</div>

#### 🔢 Code to reproduce

I have an existing contract which I need to upgrade to a newer version. This newer version has its own new `initializer` method called `initializeV2` which initialises some new stuff.

How do I call `proposeUpgrade` while also specifying this initialization to happen?

eg: `upgradeProxy` has a `call` key which can be used for this:

```auto
      await upgrades.upgradeProxy(tokenV1, TokenV2, {
        kind: "uups",
        call: {
          fn: "initializeV2",
          args: [],
        },
      });

```

But I see no such option in `proposeUpgrade` ☹

---

<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:** [May 3, 2023, 9:20pm UTC](https://forum.openzeppelin.com/t/specifying-an-initializer-to-be-called-in-proposeupgrade/35985/2 "2023-05-03T21:20:33Z")

</div>

The ability to call a function with an upgrade seems to be missing from the underlying Defender APIs. I will try to confirm this. As a workaround you may need to create the Admin proposal manually, apologies.

---

<div class="post-metadata">

**Author:** ![hmm](https://avatars.discourse-cdn.com/v4/letter/h/eb9ed0/32.png) [@hmm](https://forum.openzeppelin.com/u/hmm)\
**Post date:** [May 4, 2023, 5:33am UTC](https://forum.openzeppelin.com/t/specifying-an-initializer-to-be-called-in-proposeupgrade/35985/3 "2023-05-04T05:33:08Z")

</div>

Ah that's unfortunate.

> As a workaround you may need to create the Admin proposal manually

Would this mean:

1. Use `prepareUpgrade` instead of `proposeUpgrade` to deploy the new implementation contract.
2. Goto defender UI -\> goto proxy contract -\> new proposal -\> admin action -\> `upgradeToAndCall` with the new implentation address from point #1 and the data argument encoding the new `initializeV2` function to be called?

Note: The new proposal -\> upgrade screen doesn't have the option to call a function either.

---

<div class="post-metadata">

**Author:** ![dan\_oz](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/dan_oz/32/17511_2.png) [@dan\_oz](https://forum.openzeppelin.com/u/dan_oz)\
**Post date:** [May 4, 2023, 2:16pm UTC](https://forum.openzeppelin.com/t/specifying-an-initializer-to-be-called-in-proposeupgrade/35985/4 "2023-05-04T14:16:23Z")

</div>

Hey @hmm -

Unfortunately this is a gap as of now. The Defender Upgrade functionality assumes the upgrade as a standalone call.

If feasible, you could treat these as two different calls (propose upgrade and then create an admin action for this initializer).

As you mention, one possible alternative would be to submit the upgrade through the Defender UI using an Admin Action with `upgradeToAndCall`. One note here is that Defender typically stores the ABI of the implementation contract (which would not include this `upgradeToAndCall` function) but you could add it manually.

---

<div class="post-metadata">

**Author:** ![hmm](https://avatars.discourse-cdn.com/v4/letter/h/eb9ed0/32.png) [@hmm](https://forum.openzeppelin.com/u/hmm)\
**Post date:** [May 4, 2023, 2:36pm UTC](https://forum.openzeppelin.com/t/specifying-an-initializer-to-be-called-in-proposeupgrade/35985/5 "2023-05-04T14:36:15Z")

</div>

Mine is a UUPS contract so the `upgradeToAndCall` function exists on the implementation contract. Only the tiny minor annoyance of encoding the function to be called but its not a big deal.

> If feasible, you could treat these as two different calls (propose upgrade and then create an admin action for this initializer).

This also works 😃  
But I'm just worried about possible security issues. eg. implementation gets updated but the initialiser call gets frontrunned by some transaction which can misuse the uninitialized state. Using the `upgradeToAndCall` directly felt safer to me!

---

<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:** [May 4, 2023, 2:48pm UTC](https://forum.openzeppelin.com/t/specifying-an-initializer-to-be-called-in-proposeupgrade/35985/6 "2023-05-04T14:48:15Z")

</div>

Yes preferably you should upgrade and initialize atomically.
