Removing Your Smart Contract from a Testnet with Solidity’s Self Destruct

When developing Dapps, you will eventually need to deploy your app the a testnet like Rospen. When doing this, you have an option to self destruct – something you can’t do on the main net. This is helpful to keep the test net clean. Here is how we would implement this.

pragma solidity ^0.4.23;

contract Mortal {
    address owner;

    function Mortal() public {
      owner = msg.sender;
    }

    function kill() public {
      if (msg.sender == owner) selfdestruct(owner);
    }
}


contract Example is Mortal {
}

And that’s it! now you can call kill on your Example contract to remove it from the testnet.