# Cannot Upgrade UpgradeableContract

**URL:** <https://forum.openzeppelin.com/t/cannot-upgrade-upgradeablecontract/27569>\
**Category:** Upgrades\
**Tags:** erc20, proxies, upgrades, bep20, etherscan-verify\
**Created:** [April 13, 2022, 6:17pm UTC](https://forum.openzeppelin.com/t/cannot-upgrade-upgradeablecontract/27569 "2022-04-13T18:17:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrekat](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@andrekat](https://forum.openzeppelin.com/u/andrekat)\
**Post date:** [April 13, 2022, 6:17pm UTC](https://forum.openzeppelin.com/t/cannot-upgrade-upgradeablecontract/27569/1 "2022-04-13T18:17:16Z")

</div>

I am trying to upgrade an already deployed contract. Unfortunately I receive an `Ownable: caller is not the owner` error. Checking the actual owner of the contract at [bscscan.com](http://bscscan.com) shows me the address that I am using (so I am the owner) for the upgrade. Also calling functions (sending transactions) that are allowed only as admin works fine (through the proxy).

My Contract has Implemented the OwnableUpgradeable as well as the ContextUpgradeable and IERC20Upgradeable contract. My "initializer" function is also marked with the "initializer" modifier and was actually called since some properties were set.

Any thoughts / ideas appreciated!

#### 🔢 Code to reproduce

This is the code I am running to upgrade my contract (removed some parts of a function).

```auto
	const factory = await ethers.getContractFactory('MyContract', {
		signer: deployer,
	})

	const contract = (await upgrades.upgradeProxy(
		contractAddress,
		factory
	)) as MyContract

```

#### 💻 Environment

Hardhat

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [April 13, 2022, 6:32pm UTC](https://forum.openzeppelin.com/t/cannot-upgrade-upgradeablecontract/27569/2 "2022-04-13T18:32:28Z")

</div>

What kind of proxy are you using (transparent or UUPS)? Can you ensure that you are checking the actual owner using the proxy address (on bscscan), not the implementation address?

If possible, can you share the code for your implementation contract (or at least the `_authorizeUpgrade` function if you are using UUPS)?

---

<div class="post-metadata">

**Author:** ![andrekat](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@andrekat](https://forum.openzeppelin.com/u/andrekat)\
**Post date:** [April 13, 2022, 6:58pm UTC](https://forum.openzeppelin.com/t/cannot-upgrade-upgradeablecontract/27569/3 "2022-04-13T18:58:53Z")

</div>

Hey! Thanks for your response.

I am pretty sure that I have checked the proxy address since bscscan showed me the upgrade functions (see screenshot below).

 ![image](https://us1.discourse-cdn.com/flex022/uploads/zeppelin/original/2X/9/9f884027d41ce619396ac23d3e98ff53832a5207.png)

Side note: I've also tried to call here the "upgradeTo" function, but it results in an revert as well. New version of the implementation is deployed, but the last part of the "upgradeProxy()" function is missing / reverting.

I think that I am using a "transparent" proxy - at least I followed this example from the docs [https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable](https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable) (and I don't have the `_authorizeUpgrade` function implemented - I mean, it could be in one of the libraries I have imported)

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [April 13, 2022, 8:06pm UTC](https://forum.openzeppelin.com/t/cannot-upgrade-upgradeablecontract/27569/4 "2022-04-13T20:06:18Z")

</div>

Since you are using a transparent proxy, ensure that the account from which you are invoking the upgrade is actually the admin. For example, if you call [admin()](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.5.0/contracts/proxy/transparent/TransparentUpgradeableProxy.sol#L63), does it return the address of the account that you are using to call the upgrade?

---

<div class="post-metadata">

**Author:** ![andrekat](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@andrekat](https://forum.openzeppelin.com/u/andrekat)\
**Post date:** [April 14, 2022, 10:00am UTC](https://forum.openzeppelin.com/t/cannot-upgrade-upgradeablecontract/27569/5 "2022-04-14T10:00:08Z")

</div>

That's the weird part - when I try to call the "admin()" write function it also results in a revert (see screenshot)

![image](https://us1.discourse-cdn.com/flex022/uploads/zeppelin/original/2X/4/47ccb99375f90d8327b70651ce431668e49e3c7a.png)

Really running out of ideas - calling functions that are marked with the "onlyOwner" modifier of the implementation (through the proxy) works also fine.

---

<div class="post-metadata">

**Author:** ![andrekat](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@andrekat](https://forum.openzeppelin.com/u/andrekat)\
**Post date:** [April 14, 2022, 10:37am UTC](https://forum.openzeppelin.com/t/cannot-upgrade-upgradeablecontract/27569/6 "2022-04-14T10:37:47Z")

</div>

Ok, I have found something very interesting. I checked the logs of the `Create contract` transaction and found an event called `AdminChanged` besides three other events. The log contains two parameters `previousAdmin & newAdmin`. `previousAdmin` equals the zero-address and `newAdmin` is an address that I did not send the transaction from.

Long story short: I can see the creation transaction of my wallet. But the `AdminChanged` event contains a completely different address. Things are getting more weird: This address is another contract of type `ProxyAdmin` that was created 30 days earlier then my contract creation. But, somehow I am the creator of this contract (just with a different wallet).

**EDIT:** This contract is another upgradeable contract I deployed a month earlier. Weird part now is, why this contract is the admin of my new deployed proxy.

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [April 14, 2022, 2:27pm UTC](https://forum.openzeppelin.com/t/cannot-upgrade-upgradeablecontract/27569/7 "2022-04-14T14:27:31Z")

</div>

Thank you for that information. From what you described, here is what is happening:

- For transparent proxies, a **proxy admin contract** is deployed. The upgrades plugins will only deploy a single proxy admin contract for all of your transparent proxies on each network.  
That means if you deployed a transparent proxy a month earlier (where the plugins deployed a proxy admin), and then you deploy another transparent proxy now, the plugin will reuse that same proxy admin contract for your new proxy.
- The `AdminChanged` event was emitted by the `_changeAdmin` function that was [called in the constructor of the transparent proxy](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.5.0/contracts/proxy/transparent/TransparentUpgradeableProxy.sol#L40). In other words, that was simply setting the admin of the proxy to be your proxy admin contract.
- In order to upgrade your proxy, you should invoke the `upgrade()` function on the **proxy admin contract**. The proxy admin's `upgrade()` function calls the proxy's `upgradeTo()`.

For more details, see [https://docs.openzeppelin.com/contracts/4.x/api/proxy#TransparentUpgradeableProxy](https://docs.openzeppelin.com/contracts/4.x/api/proxy#TransparentUpgradeableProxy) and [https://docs.openzeppelin.com/contracts/4.x/api/proxy#ProxyAdmin](https://docs.openzeppelin.com/contracts/4.x/api/proxy#ProxyAdmin)
