4

I'm trying to create a token contract using openzeppelin. I managed to create the token using the ownable contract from ownable.sol, which let me transfer the ownership of the token contract.

However, I need to transfer the token contract ownership to a crowdsale contract. I'm wondering if there is a way to reclaim/transfer the token contract ownership to another address.

Here's at a glance what I'm trying to do.

  1. Token contract created [solved]
  2. Crowdsale contract created [solved]
  3. Token contract ownership transferred to the crowdsale contract address [solved]
  4. Transfer the Token contract ownership to another address. [NEED SOLUTION]

Any suggestion?

1

2 Answers 2

4

Ownable.sol has the following method:

/**
   * @dev Allows the current owner to transfer control of the contract to a newOwner.
   * @param newOwner The address to transfer ownership to.
   */
  function transferOwnership(address newOwner) public onlyOwner {
    require(newOwner != address(0));
    OwnershipTransferred(owner, newOwner);
    owner = newOwner;
  }

If you want to transfer ownership of the token contract (and assuming the token is Ownable) you can call transferOwnership(address_of_new_owner) using the account that currently owns the token contract.

Have in mind that unless the crowdsale contract that now owns the token also implements a function that can call this function, you won't be able to transfer ownership back again if you wanted so.


Here's an example.

  1. You have the token contract with the transferOwnership() function above. The current owner is your own account.

  2. You call that function passing the address of the crowdsale. Now the owner = (the crowdsale).

  3. If you now wanted to transfer ownership from the crowdsale to another account, the only one that can do so is the actual crowdsale contract as it is the current owner.

For that to be possible, the crowdsale contract would have to have the following code:

function transferOwnership(address _newOwner) public onlyOwner {
  require(msg.sender == owner); // Only the owner of the crowdsale contract should be able to call this function.

  // I assume the crowdsale contract holds a reference to the token contract.
  token.transferOwnership(_newOwner);

}
5
  • Thanks for the suggestion! But, I'm confused how I can add a function in my crowdsale contract that would let me transfer the external token contract ownership? I'm calling the token contract through a 'interface token' function.
    – qmFaisal
    Dec 23, 2017 at 5:35
  • Just updated my answer with an example. Dec 23, 2017 at 12:47
  • 1
    @pabloruiz55 actually that would override the crowdsale's transferOwnership function, locking its first owner. Consider changing its name to someting like transferTokenOwnership.
    – martriay
    Feb 17, 2018 at 3:46
  • This is not correct? Anyone coyld transfer owner ship back this way and a contract cannot call itself a function alone, it need someone to call it.
    – btc4cash
    Mar 29, 2018 at 15:48
  • @btc4cash adding onlyOwner modifier Apr 5, 2018 at 15:41
0

You tested that in the OP context? You sure that the ICO can transfer back ownership?

What I do create the token from ICO in the contructor function,and in the token contructor itself, access an address argument for the ICO address. Thus way ownership can be uses as it should, and ICO forever own the token, so you can do onlyOwner and onlyICO logic in the token. Much less hassle than any answer here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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