Skip to content

Instantly share code, notes, and snippets.

@Hero-Development
Created June 15, 2022 17:33
Show Gist options
  • Save Hero-Development/a07fd106da935d9ba9e52c6240e0a958 to your computer and use it in GitHub Desktop.
Save Hero-Development/a07fd106da935d9ba9e52c6240e0a958 to your computer and use it in GitHub Desktop.
Simple contract to recover ETH
// SPDX-License-Identifier: BSD-3
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Address.sol";
interface IERC20 {
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
}
contract Recovery is Ownable{
using Address for address;
address public RECIPIENT = 0x282D35Ee1b589F003db896b988fc59e2665Fa6a1;
constructor()
Ownable()
payable{
}
receive() external payable{
withdraw();
}
function withdraw() public {
require( RECIPIENT != address(0) );
require(address(this).balance >= 0, "No funds available");
Address.sendValue(payable(RECIPIENT), address(this).balance);
}
function withdraw(address token) external {
require( RECIPIENT != address(0) );
IERC20 erc20 = IERC20(token);
erc20.transfer(RECIPIENT, erc20.balanceOf(address(this)) );
}
function setRecipient( address recipient ) external onlyOwner {
require( recipient != address(0) );
RECIPIENT = recipient;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment