2

I am following the zeppelinOS documentation here and sumarized you execute:

zos init my-project #init zeppelinOS
zos add MyContract #register
zos session --network local --expires 3600 #open session
zos push #update code
zos create MyContract --init initialize --args 42,hitchhiker #deploy and call initialize() which can all be done just once

Now that it is deployed you can add/change functions and call again

zos update MyContract #redeploy under same address and call initialize(42, "hitchhiker")

But now imagine this UseCase. A new variable foo is added. It makes sense to add foo to the initialize() method. But how do I call initialize() now to assign foo=bar?

Of course I call

zos push

#problem: doesn't know default of new parameter
zos update MyContract

problem: doesn't know default of new parameter and ignores it

What does not work:

#does not work because contract address changes
zos create MyContract --init initialize --args 42,hitchhiker,bar

#I guessed that command. First seems to work but does not. It reverts...
zos update MyContract --init initialize --args 42,hitchher,bar

#manually calling via truffle console because can only be called once
myContract.initalize(42,"hitchhiker","bar")
2

I suspect that since your proxy has already been initialized via Initializable.sol, the private state variable "initialized" is set to true, hence you cannot call initialize again in this particular proxy instance.

If you create a new proxy, linked to a logic contract that has the 3 parameters it should work, but not for a proxy that has already been initialized. So, I would (1) add the new initializer with 3 params to your logic contract in case you want to create new proxies and (2) add a separate function to upgrade a proxy with the new foo variable, making sure that this too can only be called once, something like:

upgrade(uint _foo) {
  require(foo === 0);
  foo = _foo;
}

More info at https://github.com/zeppelinos/zos/issues/417

You can see the source code of the Initializable contract at https://github.com/zeppelinos/zos/blob/master/packages/lib/contracts/Initializable.sol

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.