Improve error message about wrong proxy admin when 0x0
I'm trying to follow the instructions for using the upgrades plugin for hardhat. I have the exact same scripts (except with my contract instead of Box) shown here: https://docs.openzeppelin.com/upgrades-plugins/1.x/hardhat-upgrades#script-usage
If I deploy in the first script, then use the address from that script's log in the upgrade script, I get the following error:
$ hh run scripts/deploy.js
Implementation V1 deployed to: 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
$ hh run scripts/upgrade.js
Error: Proxy admin is not the one registered in the network manifest
at Proxy.upgradeProxy (/work/hardhat-test/node_modules/@openzeppelin/hardhat-upgrades/src/upgrade-proxy.ts:79:13)
If I combine the initial deploy and the upgrade in the same script it works fine (similar to the Usage in Tests section at the bottom of the page).
This only happens when using the default hardhat network VM. If I connect to a local network (ganache), the upgrade works fine.
Any help would be appreciated. Thanks!
Hi @bmcd,
I was able to reproduce by running the create and upgrade scripts with hardhat spinning up a network each time.
This is because hardhat is creating a new network for each run of the script, so the ProxyAdmin isn't found when we try to do an upgrade on a new (empty) network.
$ npx hardhat run scripts/create-box.js
Box deployed to: 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
$ npx hardhat run scripts/upgrade-box.js
(node:7922) UnhandledPromiseRejectionWarning: Error: Proxy admin is not the one registered in the network manifest
...
To resolve we can create a local hardhat network (see: https://docs.openzeppelin.com/learn/deploying-and-interacting).
In another terminal, run
$ npx hardhat node
Then we can run the scripts specifying that we are using the localhost network:
$ npx hardhat run --network localhost scripts/create-box.js
Box deployed to: 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
$ npx hardhat run --network localhost scripts/upgrade-box.js
Box upgraded
We should improve the error check to better detect this situation and suggest running hardhat node to fix it.
I thought that might be the case, but since the error message said something is wrong with the Proxy admin, rather than saying the contract doesn't exist, it made me think it might be something else.
Making the error more clear would be great, plus maybe a note about the default hardhat network in the docs.
Thanks for the responses!