# OpenZeppelin Upgrades: Step by Step Tutorial for Hardhat

**URL:** <https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580>\
**Category:** Guides and Tutorials\
**Tags:** upgrades-plugins, hardhat\
**Created:** [August 18, 2020, 4:00pm UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580 "2020-08-18T16:00:02Z")\
**Posts on this page:** 20\
**Page:** 2

<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:** [August 19, 2021, 9:16pm UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/23 "2021-08-19T21:16:32Z")

</div>

Sorry, the other tutorial you've seen is the closest it gets: [UUPS Proxies: Tutorial (Solidity + JavaScript)](https://forum.openzeppelin.com/t/uups-proxies-tutorial-solidity-javascript/7786)

---

<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:** [August 20, 2021, 12:43pm UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/24 "2021-08-20T12:43:49Z")

</div>

Split this topic on August 20, 2021, 12:43pm UTC

A post was split to a new topic: [Execute upgrade using different signer](https://forum.openzeppelin.com/t/execute-upgrade-using-different-signer/14264)

---

<div class="post-metadata">

**Author:** ![hasanza](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/hasanza/32/8321_2.png) [@hasanza](https://forum.openzeppelin.com/u/hasanza)\
**Post date:** [August 21, 2021, 1:19am UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/25 "2021-08-21T01:19:45Z")

</div>

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.

---

<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:** [August 21, 2021, 3:54pm UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/26 "2021-08-21T15:54:13Z")

</div>

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' }`

---

<div class="post-metadata">

**Author:** ![Yosuke\_Aramaki](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/yosuke_aramaki/32/9067_2.png) [@Yosuke\_Aramaki](https://forum.openzeppelin.com/u/Yosuke_Aramaki)\
**Post date:** [September 21, 2021, 4:11am UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/28 "2021-09-21T04:11:34Z")

</div>

@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 ?

---

<div class="post-metadata">

**Author:** ![Skyge](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skyge/32/343_2.png) [@Skyge](https://forum.openzeppelin.com/u/Skyge)\
**Post date:** [September 21, 2021, 7:36am UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/29 "2021-09-21T07:36:36Z")

</div>

Hi, welcome! 👋

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](https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#initializers)

---

<div class="post-metadata">

**Author:** ![Yosuke\_Aramaki](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/yosuke_aramaki/32/9067_2.png) [@Yosuke\_Aramaki](https://forum.openzeppelin.com/u/Yosuke_Aramaki)\
**Post date:** [September 21, 2021, 8:06am UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/30 "2021-09-21T08:06:52Z")

</div>

@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](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/tree/v3.3.0), but I could not find the answer by myself.

---

<div class="post-metadata">

**Author:** ![Skyge](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skyge/32/343_2.png) [@Skyge](https://forum.openzeppelin.com/u/Skyge)\
**Post date:** [September 21, 2021, 10:04am UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/31 "2021-09-21T10:04:09Z")

</div>

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.

> [@Yosuke\_Aramaki](#):
>
> Also, do you know any other option other than `store` ?

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`

---

<div class="post-metadata">

**Author:** ![Yosuke\_Aramaki](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/yosuke_aramaki/32/9067_2.png) [@Yosuke\_Aramaki](https://forum.openzeppelin.com/u/Yosuke_Aramaki)\
**Post date:** [September 21, 2021, 12:35pm UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/32 "2021-09-21T12:35:55Z")

</div>

@Skyge Thank you. I really appreciate your answer.  
Now I understand `store` comes from contract's functions, and we can call a contract function by using initialize option with deploy.

---

<div class="post-metadata">

**Author:** ![TJakubek](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/tjakubek/32/9343_2.png) [@TJakubek](https://forum.openzeppelin.com/u/TJakubek)\
**Post date:** [October 7, 2021, 10:15pm UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/33 "2021-10-07T22:15:49Z")

</div>

Hi, amazing tutorial.  
I think I have it more or less figured out but I am having an issue with typescript in tests and deployments.  
For un-upgradeable contracts I am able to use a type from the typechain, so I have all the functions of the contract available.

On the other hand, when I use the upgrades.deployProxy function the return type is Contract and all methods are lost. Is there a way around this or am I doing something wrong?

---

<div class="post-metadata">

**Author:** ![ruham88](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@ruham88](https://forum.openzeppelin.com/u/ruham88)\
**Post date:** [October 14, 2021, 6:59pm UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/34 "2021-10-14T18:59:44Z")

</div>

Hi, thanks for the tutorial. I followed it step by step, and at the end it doesn't keep the store.  
`await box2.retrieve()` returns 0 instead of `'42'`, however, all the tests pass.  
What can be the reason of it? Am I missing an important step here?

---

<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:** [October 14, 2021, 7:01pm UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/35 "2021-10-14T19:01:14Z")

</div>

The Upgrades plugin doesn't directly support TypeChain yet. Sorry about that. You can probably do manual casting of the return type in the meantime...

---

<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:** [October 14, 2021, 7:02pm UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/36 "2021-10-14T19:02:40Z")

</div>

You may be using the wrong address when you call the `attach` method.

---

<div class="post-metadata">

**Author:** ![ruham88](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@ruham88](https://forum.openzeppelin.com/u/ruham88)\
**Post date:** [October 14, 2021, 7:07pm UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/37 "2021-10-14T19:07:03Z")

</div>

I checked it several times, I copy the output of Box.sol deployment, then paste it into `prepare_upgrade.js`. I can see that the increment() function is there, and it works, however the initial state is 0 when I retrieve first.

As you can see on the screenshot below. If it's the wrong address, then which one I should paste? Also, note, that all tests are passing. Would really appreciate help here!

 ![Untitled](https://us1.discourse-cdn.com/flex022/uploads/zeppelin/original/2X/6/61d92d1e332a229e6dae01112b0de4d9cc865d05.png)

![Un3titled](https://us1.discourse-cdn.com/flex022/uploads/zeppelin/original/2X/0/04d96a21ba5cce92381886f952f7b4a760be4a36.png)

 ![U2ntitled](https://us1.discourse-cdn.com/flex022/uploads/zeppelin/original/2X/a/a49729813bb9f5868a3b5eab020cf05ad840bfeb.png)

---

<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:** [October 14, 2021, 7:19pm UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/38 "2021-10-14T19:19:59Z")

</div>

The address is wrong, you need to attach the proxy address (in your case `0x1E24...`). The address shown in the console is the address of the implementation contract, which you should not interact directly with.

---

<div class="post-metadata">

**Author:** ![nunezlt](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@nunezlt](https://forum.openzeppelin.com/u/nunezlt)\
**Post date:** [October 18, 2021, 10:45pm UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/39 "2021-10-18T22:45:51Z")

</div>

What if instead of a multisig you want a community of token holders to approve an upgrade? How could we implement that without bypassing all the safety that the upgrades plugin provide?

---

<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:** [October 18, 2021, 10:56pm UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/40 "2021-10-18T22:56:16Z")

</div>

The Upgrades plugin runs off chain and there is no way to enforce it on chain. Even with a multisig setup you're not using the plugin itself to upgrade. In the governance proposal for the upgrade you should include a link where people can verify the code of the new contract implementation, and where they could also verify upgade safety by themselves through running a test suite that uses the Upgrades plugin.

---

<div class="post-metadata">

**Author:** ![night-king](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/night-king/32/11083_2.png) [@night-king](https://forum.openzeppelin.com/u/night-king)\
**Post date:** [December 17, 2021, 7:30am UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/41 "2021-12-17T07:30:58Z")

</div>

help.

I completed all upgrades contract follow this Topic, thanks!  
I **transferred ownership to Gnosis Safe.**

deployed my ERC1155 Contract:

```auto
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

contract MyToken is Initializable, ERC1155Upgradeable, OwnableUpgradeable, UUPSUpgradeable {
    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() initializer {}

    function initialize() initializer public {
        __ERC1155_init("https://akjx.com/token/{id}");
        __Ownable_init();
        __UUPSUpgradeable_init();
    }

    function setURI(string memory newuri) public onlyOwner {
        _setURI(newuri);
    }

    function mint(address account, uint256 id, uint256 amount, bytes memory data)
        public
        onlyOwner
    {
        _mint(account, id, amount, data);
    }

    function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
        public
        onlyOwner
    {
        _mintBatch(to, ids, amounts, data);
    }

    function _authorizeUpgrade(address newImplementation)
        internal
        onlyOwner
        override
    {}
}

```

now, I want to call **setURI** method, I found it is impossible to connect contract, [OpenZeppelin] app( Gnosis Safe's apps) only support upgrades.

 ![Snipaste_2021-12-17_15-31-42](https://us1.discourse-cdn.com/flex022/uploads/zeppelin/original/2X/6/63fa6bf63b95d88a86a16c708d4a06318b06a883.png)

Does anyone know how to connect my Gnosis Safe wallet to call **setURI** method？

---

<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:** [December 22, 2021, 4:36pm UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/42 "2021-12-22T16:36:21Z")

</div>

To call functions on your contract you go through the normal Gnosis Safe process, not our OpenZeppelin app. Look for the "Transaction Builder" app in "Apps".

---

<div class="post-metadata">

**Author:** ![Shahbaz\_Ali](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/shahbaz_ali/32/12643_2.png) [@Shahbaz\_Ali](https://forum.openzeppelin.com/u/Shahbaz_Ali)\
**Post date:** [January 25, 2022, 2:01pm UTC](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580/43 "2022-01-25T14:01:05Z")

</div>

Hi abcoathup  
Can you tell me about it  
"  
I want to ask that we've deployed an up-gradable contract yesterday on polygon by hardhat plugin and it was deployed in one single transaction and now today we're deploying the same up-gradable contract now from same hardhat it's deploying in 3 transactions can you tell me why it's taking 2 extra transactions?

contract address deployed in one single transaction:0x6a4581fffdeaC8246B2DC3662F1035B6F5E8e618  
"

[Previous page](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580.md?page=1)

[Next page](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580.md?page=3)
