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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s