Inheritance Assignment

Destroyable.sol:

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

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

Changed owner variable to payable in Ownable.sol:

address payable public owner;

imported Destroyable and made HelloWorld inherit from it.

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

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

contract Destroyable is Ownable {
    
    function destroyContract() public onlyOwner {
        selfdestruct(msg.sender);
    }
}
1 Like
  • HelloWorld.sol

[spoiler]

import "./Ownable.sol";
import "./Destroyable.sol";

pragma solidity 0.5.12;

contract HelloWorld is Ownable, Destroyable{

[/spoiler]

  • Ownable.sol
    [spoiler]
    address payable public owner;
    [/spoiler]

  • Destroyable.sol
    [spoiler]

import "./Ownable.sol";

pragma solidity 0.5.12;

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

[/spoiler]

3 Likes

Showoff!! :face_with_raised_eyebrow:

But I’m still impressed like last time. :astonished:

Now you have to continue like this. You just set the standard, bro.

I look forward to your next reply, what have you come up with then? To be continued… :hugs:

Ivo

1 Like

I love this
[spoiler]
[spoiler] [/spoiler] Tag, Super cool :nerd_face: :+1:
[/spoiler]
I will use it everywhere now

3 Likes

It’s cool right?
I like it too.

1 Like

import “./Ownable.sol”;
pragma solidity 0.5.12;

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

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

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

1 Like

destroyable.sol

import “./Ownable.sol”;
pragma solidity 0.5.12;

function close() public onlyOwner {
selfdestruct(msg.sender);
}

helloworld.sol

import “./Ownable.sol”;
import “./Destroyable.sol”;
pragma solidity 0.5.12;

contract HelloWorld is Ownable, Destroyable {

1 Like
pragma solidity 0.5.12;

contract SelfDestruct {
    constructor() public payable {
        
    }

    function kill(address payable to) public {
        selfdestruct(to);
    }
}
1 Like

H mark.

You have forgot the contract in the destroyable.sol. LIke this.

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

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

}
1 Like

Thank you, will update.

1 Like

Hi Ivo,
I did the reverse:

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

contract Ownable is SelfDestruct{
    address public owner;
    
    modifier onlyOwner(){
        
        require(msg.sender == owner);
        _; //Continue execution
    }
    constructor() public{
        owner = msg.sender;
    }       
}

and then I did:

import "./Ownable.sol";
pragma solidity 0.5.12;
//this is how to write a inheritance
contract HelloWorld is Ownable{

    struct Person {
      uint id;
      string name;
      uint age;
      uint height;
      bool senior;
    }

did not copy the whole file. Sorry about that, I should have these steps before.

1 Like

pragma solidity 0.5.12;

contract Destroyable {
address public owner;

function close() public onlyOwner{
    require(msg.sender == owner);
    selfdestruct(owner);
}

}

1 Like

import ‘./Ownable.sol’;
pragma solidity 0.5.12;

contract Destroyable is Ownable{

function close() public onlyOwner { //onlyOwner is custom modifier
   selfdestruct(owner);  // `owner` is the owners address

}

}

1 Like

Hi.

onlyOwner in your function, will not work as it is not defined in this contract.
To use onlyOwner, you must import "./ownable.sol"; and start the contract like this :

contract Destroyable is Ownable{

}

Ivo

import “./Ownable.sol”;
pragma solidity 0.5.12;

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

and

import “./Ownable.sol”;
import “./Destroyable.sol”;
pragma solidity 0.5.12;

contract BasicSolidty is Ownable, Destroyable
{

import “./Ownable.sol”;
pragma solidity 0.5.12;

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

and

import “./Ownable.sol”;
import “./Destroyable.sol”;
pragma solidity 0.5.12;

contract BasicSolidty is Ownable, Destroyable
{

1 Like

Hi, Kav.

In theory, Since you already imported Ownable.sol in contract Destroyable. You don’t need to import Ownable.sol in your BasicSolidity contract to.

Ivo

1 Like

in destroyable: :sweat_smile:

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

contract destroyable is ownable{ 
    
        function close() public onlyOwner {
      selfdestruct(owner); 
    }
}

in HelloWorld:

import "./ownable.sol"
import "./destroyable.sol"

pragma solidity 0.5.12;

contract HelloWorld is ownable, destroyable{....
1 Like