0

I have a contract WidgetMaker that uses Zeppelin-Solidity Ownable to ensure that only the owner of the contract can execute SendWidget.

At present, the contract is owned by my own wallet address and I have a web3 app that lets me execute this function no problem.

I want to migrate from this setup to one where the function SendWidget can be called by another contract WidgetManager. This needs to be the same deployed instance of WidgetMaker, so I will need to transfer ownership to the new contract.

Transferring ownership is no problem as this is already taken care of by OpenZeppelin code. I have two questions:

1) How do I securely deploy WidgetManager to allow it to call the SendWidget function on the current deployed instance of WidgetMaker?

2) Is there a safe way to add a function to WidgetManager that would allow it to pass the ownership back to me, or to another contract in the future if I wanted to upgrade the system while still keeping the same deployed instance of WidgetMaker?

1

You've got the right idea.

As you note, you can easily transfer ownership away because you've got the owner key initially. You can do that manually and just be really, really careful, or you can automate it with a migration script using something like Truffle. In any case, it's a deployment process.

It's not the only way to do step 1. Another way to go that is clean but a little hard on the one-time deployment gas budget, is to make deploying the WidgetMaker part of the WidgetManager's constructor. Done that way, when you deploy a WidgetManager it will deploy its own factory and have ownership by default. Something like:

contract WidgetMaker {
  // ...
}

contract WidgetManager {

  WidgetMaker maker;

  function WidgetManager() public {
    maker = new WidgetMaker();
  }

  // ...
}

You'll want to get the ownership back. Follow the same "push" pattern and have the "owner" push it back to you. Something like:

contract WidgetMaker is Owned {
  // ...
}

contract WidgetManager is Owner {
  // ...
  function changeWidgetMakerOwner(address newOwner) public onlyOwner returns(bool success) {
    require(newOwner != 0); // in case they forget to pass an address
    maker.changeOwner(newOwner); // "this" is the current owner, so it can call the function once.
    LogMakerOwnerChanged(msg.sender, newOwner);
    return true;

}

Hope it helps.

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.