Self Destruct method of Smart Contract in Solidity


Here is the code example how can we destruct a contract. For destruction we have to set the payable address in selfdestruct method where all ethers of contract can be transferred. After destruct a contract all state variables become null, 0 or false, also we can’t update any state variable. e.g.

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;


contract selfDestructContract{
    
    bool state = false;
    uint count = 10;
    
    constructor() payable {
        
    }
    
    
    function destruct()public {
        selfdestruct(payable(msg.sender));
    }
    
    function getbalance()public view returns(uint){
        return address(this).balance;
    } 
    
    function toggleState()external{
        state = !state;
    }
    
    function getState()public view returns(bool){
        return state;
    }
    
    function increment()public{
        count++;
    } 
    
    function getCount()public view returns(uint){
        return count;
    }
    
}
, ,