Created
August 14, 2022 14:52
-
-
Save anvie/61d038edf1ae3459b68c57d4460af321 to your computer and use it in GitHub Desktop.
Fallback and self destruct Solidity example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
contract FallbackAndSelfDestructExample is Ownable { | |
function destroy(address _addr) external onlyOwner { | |
address payable addr = payable(address(_addr)); | |
selfdestruct(addr); | |
} | |
// This fallback function | |
// will keep all the Ether | |
receive() external payable { | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment