Created
May 15, 2021 03:21
-
-
Save littlekfc/2c103ab0034d79e987eca27549292a8e to your computer and use it in GitHub Desktop.
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
pragma solidity =0.6.6; | |
interface IERC20 { | |
event Approval(address indexed owner, address indexed spender, uint value); | |
event Transfer(address indexed from, address indexed to, uint value); | |
function name() external view returns (string memory); | |
function symbol() external view returns (string memory); | |
function decimals() external view returns (uint8); | |
function totalSupply() external view returns (uint); | |
function balanceOf(address owner) external view returns (uint); | |
function allowance(address owner, address spender) external view returns (uint); | |
function approve(address spender, uint value) external returns (bool); | |
function transfer(address to, uint value) external returns (bool); | |
function transferFrom(address from, address to, uint value) external returns (bool); | |
} | |
contract AirDrop { | |
address private owner; | |
constructor() public payable { | |
owner = msg.sender; | |
} | |
// modifier to check if caller is owner | |
modifier isOwner() { | |
// If the first argument of 'require' evaluates to 'false', execution terminates and all | |
// changes to the state and to Ether balances are reverted. | |
// This used to consume all gas in old EVM versions, but not anymore. | |
// It is often a good idea to use 'require' to check if functions are called correctly. | |
// As a second argument, you can also provide an explanation about what went wrong. | |
require(msg.sender == owner, "Caller is not owner"); | |
_; | |
} | |
function airdropToken(address[] calldata to, address token, uint amountOut) external payable isOwner() { | |
for (uint i = 0; i < to.length; i ++) { | |
require( IERC20(token).transfer(to[i], amountOut) , "airdrop token error"); | |
} | |
} | |
function airdropETH(address payable[] calldata to, uint amountOut) external payable isOwner() { | |
for (uint i = 0; i < to.length; i++) { | |
to[i].transfer(amountOut); | |
} | |
} | |
function drainToken(address token) external payable isOwner() { | |
require( IERC20(token).transfer(msg.sender, IERC20(token).balanceOf(address(this))) , "drain ERROR"); | |
} | |
function drainETH() external payable isOwner() { | |
msg.sender.transfer(address(this).balance); | |
} | |
function changeOwner(address newOwner) external isOwner() { | |
owner = newOwner; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment