1

How can i make function call from one contract deployed on the blockchain to another contract seperately deployed on the blockchain to transfer ownership from the second (called) contract to a new address or contractaddress?

Hi!

So i deployed a tokencontract with the msg.sender address as the owner.

After i deployed the crowdsale contract (which needs ownership of the tokencontract to mint, burn and transact tokens) and i used the function transferOwnership() to transfer the token ownership to the crowdsale contract address.

This works, but then i need to change it back to another address, of course, it does not.

I need to have a function that directly calls the token contract address and gives as a parameter the new owner address.

How should i implement this?

1 Answer 1

1

Assuming you have the token contract in a state variable called token, it would simply look something like this:

function transferTokenOwnership(address newOwner) public {
    // check msg.sender here to make sure it's authorized

    token.transferOwnership(newOwner);
}
5
  • assuming the token contract transferOwnership function has the usual onlyOwner type modifier, wouldn't msg.sender of this call have to be the crowdsale contract address in this case?
    – TC8
    Jan 31, 2018 at 11:38
  • 1
    Yes, msg.sender in the token contract's transferOwnership will be the crowdsale contract, since the crowdsale contract is what's calling the function.
    – user19510
    Jan 31, 2018 at 11:39
  • Am i right in thinking this will only work where the crowdsale contract has the Ownable interface? i.e. if it hadn't imported the Ownable contract it wouldn't be able to make this call?
    – TC8
    Jan 31, 2018 at 11:45
  • 1
    This will work as long as token is of a type that defines transferOwnership. There are no requirements on the crowdsale contract.
    – user19510
    Jan 31, 2018 at 11:48
  • thanks for clarifying, much appreciated! @Papi Junior, you should accept smarx's answer given that it worked - standard StackExchange behaviour :)
    – TC8
    Jan 31, 2018 at 11:51

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.