Inheritance Assignment

import "./onlyowner.sol";
pragma solidity 0.5.12;


contract Destroyable is Ownable {
        function destroy() public onlyOwner { 
                       
                 selfdestruct(msg.sender);  
           
        }
}
1 Like

Contract Destroyable.sol

import "./Ownable.sol";
pragma solidity 0.5.12;

contract Destroyable is Ownable{
    
    function destroy() public onlyOwner {
    selfdestruct(msg.sender);  
    }
}

Parent Contract

import "./Ownable.sol";
import "./Destroyable.sol";
pragma solidity 0.5.12;

contract HelloWorld is Ownable, Destroyable { 

My solution:

  1. Creating a new contract Destroyable.sol with a destroy() function :
import “./Ownable.sol”;
pragma solidity 0.5.12;

contract Destroyable is Ownable {

        function destroy(address sendTo) public onlyOwner {
                 selfdestruct(sendTo);
        }

}
  1. Importing Destroyable.sol to HelloWorld.sol and declaring inheritance :
import “./Ownable.sol”;
import “./Destroyable.sol”;
pragma solidity 0.5.12;

contract HelloWorld is Ownable, Destroyable { ...
1 Like

Forgot to put ; after the imports :grimacing:

@Eskild
I did it :slight_smile:

2 Likes
import "./Ownable.sol";
pragma solidity 0.5.12;

contract Destroyable is Ownable{
    
    function remove() public onlyOwner{
        selfdestruct(owner);
    }
    
}

Additionally the adress in Ownable.sol needs to be changed to “payable” as the “selfdestruct” function will send the whole contract balance to the owner address, therefore it needs to be payable.

1 Like

– Destroyable contract –

pragma solidity 0.5.12;

import "./Ownable.sol";

contract Destroyable is Ownable
{
    function destroy() public onlyOwner
    {
        address payable theOwner = address(uint160(owner));
        
        selfdestruct(theOwner);
    }
}
import "./Ownable.sol";
pragma solidity 0.5.12;

contract Destroyable is Ownable {
    function destroy() public onlyOwner {
      selfdestruct(owner);
    }
}
1 Like

Created a new file called SelfDestruct.sol
named the contract Destroyable
imported/inherited from Ownable

import "./Ownable.sol";

pragma solidity 0.5.12;

contract Destroyable is Ownable {
    
  
    
function destroy() public onlyOwner { 
    address payable receiver = msg.sender;
  selfdestruct(receiver);  
}

}

In Hello World
imported/inherited from Ownable and Destroyable

import "./Ownable.sol";
import "./SelfDestruct.sol";

pragma solidity 0.5.12;



contract HelloWorld is Ownable, Destroyable{
1 Like
import "./Ownable.sol";
pragma solidity 0.5.12;

contract Destroyable is Ownable {
    
    function close() public onlyOwner { //onlyOwner is custom modifier
        // Alternative method
        /*  address payable destructOwner = address(uint160(owner));
            selfdestruct(destructOwner);  // `destructOwner` is the owners address payable 
        */
        selfdestruct(msg.sender);  // msg.sender is the owners address payable 
    }
}
1 Like
import "./Ownable.sol";
pragma solidity 0.5.12;

contract Destroyable is Ownable  {
    function destroy() public onlyOwner {
        selfdestruct(msg.sender);
    }
}
1 Like
import "./Ownable.sol";
pragma solidity 0.5.12;

contract Destroyable is Ownable{
    
    function destroyContract(address payable owner) public onlyOwner { //onlyOwner is custom modifier
    
        selfdestruct(owner);  // `owner` is the owners address
        
    }
    
}
// destroyContract() can also work as private(I guess), but can't be tested with the button after we deploy the contract
1 Like

I think this should be fine… If I missed something please, let me know :smiley:

import "./Ownable.sol";
pragma solidity 0.5.12;

contract Destroyable is Ownable {
    
    
    function destroy() public onlyOwner {
        selfdestruct(msg.sender);
    }
}
1 Like
import "./Ownable.sol";

pragma solidity 0.5.12;

contract Destroyable is Ownable
{
    function selfDestruct() public onlyOwner
    {
        selfdestruct(msg.sender);
    }
}
1 Like

In a new file called Selfdestructable.sol, I wrote the following:

import"./Ownable.sol";
pragma solidity 0.5.12;

contract Selfdestructable is Ownable{
    function close() public onlyOwner{
        selfdestruct(owner);
    }
}

When I initially deployed the contract, it gave an error. After understanding the error message given and reading some additional material, I made the following amendment:

import"./Ownable.sol";
pragma solidity 0.5.12;

contract Selfdestructable is Ownable{
    function close() public onlyOwner{
        address payable owner;
        selfdestruct(owner);
    }
}

Then in the HelloWorld.sol contract, I made the following appendage:

import"./Ownable.sol";
import"./Selfdestructable.sol";
pragma solidity 0.5.12;

contract HelloWorld is Ownable, Selfdestructable{...

To test that the contract worked, I deployed the contract with a non-zero amount of wei/ether. Once I closed the contract and checked the transaction log, there was no wei/ether left in the contract. The self-destruct function worked!

1 Like

@JanjoHR1
No you didn’t miss anything :slight_smile:

2 Likes
import "./Ownable.sol";
pragma solidity 0.5.12

contract Destroyable is Ownable {
    
    function destroy() public onlyOwner{
        address payable receiver = msg.sender;
        selfdestruct (receiver);
    }
}
1 Like
pragma solidity 0.5.12;

import "./Ownable.sol";

contract Destroyable is Ownable {
    
    function destroy() public onlyOwner {
        selfdestruct(msg.sender);
    }
    
}
1 Like

Main contract file:

import "./Destroyable.sol";
pragma solidity 0.5.12;

contract SimpleTransaction is Destroyable
{
    

Destroyable.sol:

import "./Ownable.sol";
pragma solidity 0.5.12;

contract Destroyable is Ownable{

    function closeContract() public onlyOwner { //onlyOwner is custom modifier
        selfdestruct(owner);  // `owner` is the owners address
    }
}
1 Like

Nice :metal:

pragma solidity >=0.4.16 <0.7.0;

import "./Ownable.sol";

contract Destructible is Ownable {

    function destroy() public isOwner {
      selfdestruct(msg.sender);
    }
}
1 Like