OpenZeppelin Upgrades: Step by Step Tutorial for Hardhat

I feel this is a little misleading, could we change it to this:

const proxy = await upgrades.deployProxy(Box, [42], { initializer: 'store' })
console.log("Proxy of Box deployed to:", proxy.address)

Or do we want people to think that the proxy is the box? (Technically not correct, but people won’t know the difference when they interact)

1 Like

Emmmmm, I am not sure, but at least for me, I think use the implementation name is better, cause if there are two proxy contracts in a system, just use proxy will be a little confused.

True. Perhaps just a note saying that box stands for the proxy then. And maybe a note saying this deploys a proxy, proxyadmin, and implementation.

Can help new users with clarity.

1 Like

Hi @PatrickAlphaC,

Good point.

https://docs.openzeppelin.com/upgrades-plugins/1.x/api-hardhat-upgrades#deploy-proxy

I don’t have permission to change any more, so this is a note for anyone reading this.

1 Like

PR Created: https://github.com/OpenZeppelin/docs.openzeppelin.com/pull/285

1 Like

3 posts were split to a new topic: Can not deploy contract with proxy on the Optimism

A post was split to a new topic: Is there an easier way to make get the Proxy Address when using Open Zeppelin Upgrades?

I’m stuck on the penultimate step … it tells me that an address is not registered. That address does not belong to anything in the project!. I don’t know where it comes from.

The error:

Preparing upgrade...
Error: Deployment at address 0xE8f000B7ef04B7BfEa0a84e696f1b792aC526700 is not registered

I think you're preparing an upgrade for a proxy whose current implementation is that address. But it's an unknown address for the plugins, either because you didn't deploy it with the plugins in the same project, or you deleted the network file that contained its metadata.

So do you recommend that I start everything from scratch?

If that's an option for you, it will be the fastest route. Currently you can't easily. add an implementation in the network file after it has been deployed. Track issue this issue for updates: https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/175.

Is there an equivalent, detailed tutorial for the UUPS proxy pattern?

Sorry, the other tutorial you've seen is the closest it gets: UUPS Proxies: Tutorial (Solidity + JavaScript)

1 Like

A post was split to a new topic: Execute upgrade using different signer

Ah, I see. Would you be able to give me an example of what a hardhat deploy script with a UUPS contract would look like? The script I currently use (non-upgradable) deploys the contract and copies its address and ABI over to the frontend app. In a UUPS contract scenario, what might such a script look like? Thank you very much for your help so far.

If you want you can share the script in a new post and we can go over the necessary changes.

I believe all that should be required in the script is to add { kind: 'uups' }

1 Like

@abcoathup Thank you for great tutorial.
I could not understand what initializer options are.
box = await upgrades.deployProxy(Box, [42], {initializer: 'store'});

Are there any options other than 'store' ?
Any other reference about initializer ?

Hi, welcome! :wave:

I think for the initializer option, it means when you deploy a proxy contract, you want to execute a function that is equal to the constructor in the implementation contract, and for more details, I think you can have a look at the documentation: Writing Upgradeable Contracts - OpenZeppelin Docs

1 Like

@Skyge Thank you for your reply.

I understood that we can use initialize as constructor.

Could you tell me why you are using store in this sample code?
Also, do you know any other option other than store?

I tried finding these answers by reading openzeppelin source code and document, but I could not find the answer by myself.

I think the tutorial just show a way you can call a function when deploy a contract, so it can be any method you want to call, and it is ok if you want to call this function separately later.

In the tutorial, there are only three functions: store, retrieve and increment, two write data functions and one read data function, so if you do not want to call store, maybe you can try to call increment

1 Like