Upgrading Proxy contracts

Hi i have used your proxy pattern for upgradeable contract it worked fine but i have one problem. i have two variable which had some values but after deployed contarct with proxy those values getting 0. what i sholud to do for those values.

1 Like

Hi @love_chawda,

Existing state variables should maintain their state, assuming you didn’t change the order nor type of the declared state variables.

Were there any issues reported during upgrading?

It would be helpful if you could share your contract (original version and upgraded version).

uint256 public feePercent = 150;
address public feeAddress = 0x2DAB20a2b069Ad67656F4a457E898F61516c8982;

there is initial values and when i use this with proxy it is getting 0. but if i have set with setter method than it give me the setted values. but i want first time initialize with proxy call.

1 Like

Hi @love_chawda,

If you haven’t already, you may want to look at Learn guide: Upgrading Smart Contracts

I assume that your contract looks a little like the following.
When we create the contract, we need to initialize it. We can then read those values.


pragma solidity ^0.5.0;

import "@openzeppelin/upgrades/contracts/Initializable.sol";

contract MyContract is Initializable {
  uint256 public myPercent;
  address public myAddress;

  function initialize(uint256 initialMyPercent, address initialMyAddress) initializer public {
    myPercent = initialMyPercent;
    myAddress = initialMyAddress;

Deploy contract

$ oz create
✓ Compiled contracts with solc 0.5.16 (commit.9c3226ce)
? Pick a contract to instantiate MyContract
? Pick a network development
✓ Added contract MyContract
✓ Contract MyContract deployed
All contracts have been deployed
? Call a function to initialize the instance after creating it? Yes
? Select which function * initialize(initialMyPercent: uint256, initialMyAddress: address)
? initialMyPercent (uint256): 150
? initialMyAddress (address): 0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0
✓ Setting everything up to create contract instances
✓ Instance created at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601

Call contract

$ oz call
? Pick a network development
? Pick an instance MyContract at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
? Select which function myPercent()
✓ Method 'myPercent()' returned: 150
1 Like

okay thankyou i will try with this

1 Like

Hi @love_chawda,

How did you get on?

i am working on it.but i have one more question. would i call initialize method manually?

1 Like

Hi @love_chawda,

Apologies, I only saw this question.
You can call initialize as part of oz create.