Hi @Ondrej.S,
Your solution is correct, but not for the reason you have given:
That is correct, but it was already payable, because here the owner’s address is represented by msg.sender
(which is a payable address), and not the inherited state variable owner
(which is a non-payable address).
msg.sender
can only be the owner, because the function is marked onlyOwner
.
In fact, the two lines of code in your solution is a more long-winded (or some would say more clearly broken-down step-by-step) version of the following equally valid solution:
selfdestruct(msg.sender);
Have a look at this post for further details.
It’s only when we explicitly reference the owner’s address by using owner
, that we need to convert a non-payable address to a payable one, as follows:
// either
address payable receiver = address(uint160(owner));
selfdestruct(receiver);
// or
selfdestruct(address(uint160(owner)));
// OR by first making owner payable in contract Ownable:
address payable public owner;
// and then using the following code in contract Destroyable:
selfdestruct(owner);
… also, check this post out — it explains how you can make an additional adjustment in terms of the inheritance. I think you’ll find it interesting.