Skip to content

Instantly share code, notes, and snippets.

@anvie
Created August 14, 2022 14:52
Show Gist options
  • Save anvie/61d038edf1ae3459b68c57d4460af321 to your computer and use it in GitHub Desktop.
Save anvie/61d038edf1ae3459b68c57d4460af321 to your computer and use it in GitHub Desktop.
Fallback and self destruct Solidity example.
// 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