Created
December 5, 2018 09:50
-
-
Save 0x-genesys/58b7c5784102b4d89961366a93dd8a9e to your computer and use it in GitHub Desktop.
AirDrop.sol
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.4.24; | |
/** | |
* @title Token | |
* @dev Simpler version of ERC20 interface | |
*/ | |
contract Token { | |
function transfer(address to, uint256 value) public returns (bool); | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
} | |
contract Ownable { | |
address public owner; | |
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | |
/** | |
* @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
* account. | |
*/ | |
constructor() public { | |
owner = msg.sender; | |
} | |
/** | |
* @dev Throws if called by any account other than the owner. | |
*/ | |
modifier onlyOwner() { | |
require(msg.sender == owner); | |
_; | |
} | |
/** | |
* @dev Allows the current owner to transfer control of the contract to a newOwner. | |
* @param newOwner The address to transfer ownership to. | |
*/ | |
function transferOwnership(address newOwner) onlyOwner public { | |
require(newOwner != address(0)); | |
emit OwnershipTransferred(owner, newOwner); | |
owner = newOwner; | |
} | |
} | |
contract AirDrop is Ownable { | |
// This declares a state variable that would store the contract address | |
Token public tokenInstance; | |
/* | |
constructor function to set token address | |
*/ | |
constructor(address _tokenAddress) public { | |
tokenInstance = Token(_tokenAddress); | |
} | |
/* | |
Airdrop function which take up a array of address,token amount and eth amount and call the | |
transfer function to send the token plus send eth to the address is balance is 0 | |
*/ | |
function doAirDrop(address[] _address, uint256 _amount, uint256 _ethAmount) onlyOwner public returns (bool) { | |
uint256 count = _address.length; | |
for (uint256 i = 0; i < count; i++) | |
{ | |
/* calling transfer function from contract */ | |
tokenInstance.transfer(_address [i],_amount); | |
if((_address [i].balance == 0) && (this.balance >= _ethAmount)) | |
{ | |
require(_address [i].send(_ethAmount)); | |
} | |
} | |
} | |
function transferEthToOnwer() onlyOwner public returns (bool) { | |
require(owner.send(this.balance)); | |
} | |
/* | |
function to add eth to the contract | |
*/ | |
function() payable { | |
} | |
/* | |
function to kill contract | |
*/ | |
function kill() onlyOwner { | |
selfdestruct(owner); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment