0

In official documentation of Solidity about Self-destruct instruction is written:

If you want to deactivate your contracts, you should instead disable them by changing some internal state which causes all functions to revert.

Reference: https://solidity.readthedocs.io/en/latest/introduction-to-smart-contracts.html#deactivate-and-self-destruct

Can Some one explain me what does mean?

It's sufficient and correct this code to destroy a contract?:

function kill() public { if (msg.sender == owner) // only allow this action if the account sending the signal is the creator selfdestruct(owner); // kills this contract and sends remaining funds back to creator } 

Thanks a lot, I'm learning...

1 Answer 1

2

It's probably easiest to accomplish with a modifier which you add to each function. So something like this:

pragma solidity 0.6.0; contract Example { bool _isActive = true; modifier checkActive() { require (_isActive); _; } function do1() checkActive public { // do something } function do2() checkActive public { // do something else } function setActivity(bool isActive) public { // restrict access to this function _isActive = isActive; } } 

Here everything works if the contract's _isActive is true. But once someone with proper access sets that to false all function calls will revert.

And yes your selfdestruct code looks ok.

1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.