SHARE
TWEET

AirDropContractCode

a guest Jan 20th, 2018 583 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pragma solidity ^0.4.16;
  2.  
  3. contract Ownable {
  4.   address public owner;
  5.  
  6.   function Ownable() {
  7.     owner = msg.sender;
  8.   }
  9.  
  10.   modifier onlyOwner() {
  11.     require(msg.sender == owner);
  12.     _;
  13.   }
  14.  
  15.   function transferOwnership(address newOwner) onlyOwner {
  16.     require(newOwner != address(0));
  17.     owner = newOwner;
  18.   }
  19. }
  20.  
  21. interface Token {
  22.   function transfer(address _to, uint256 _value) returns (bool);
  23.   function balanceOf(address _owner) constant returns (uint256 balance);
  24. }
  25.  
  26. contract AirDrop is Ownable {
  27.  
  28.   Token token;
  29.  
  30.   event TransferredToken(address indexed to, uint256 value);
  31.   event FailedTransfer(address indexed to, uint256 value);
  32.  
  33.   modifier whenDropIsActive() {
  34.     assert(isActive());
  35.  
  36.     _;
  37.   }
  38.  
  39.   function AirDrop () {
  40.       address _tokenAddr =0xdB42E3666FDAA8751D310609Bb3c5712d1a7946F; //VRE smartcontract address
  41.       token = Token(_tokenAddr);
  42.   }
  43.  
  44.   function isActive() constant returns (bool) {
  45.     return (
  46.         tokensAvailable() > 0 // Tokens must be available to send
  47.     );
  48.   }
  49.  
  50. //
  51. //
  52. //
  53. //
  54. //below function can be used when you want to send every recipient with different number of tokens
  55. function sendTokens(address[] dests, uint256[] values) whenDropIsActive onlyOwner external {
  56.     uint256 i = 0;
  57.     while (i < dests.length) {
  58.         uint256 toSend = values[i];     //    "* 10**18" was here on this line, changed it to 10^0 because VRE has 0 decimals??? Idk.
  59.         sendInternally(dests[i] , toSend, values[i]);
  60.         i++;
  61.     }
  62.   }
  63. //
  64. //
  65. //
  66. //
  67.  
  68.  
  69. // this function can be used when you want to send same number of tokens to all the recipients
  70.   function sendTokensSingleValue(address[] dests, uint256 value) whenDropIsActive onlyOwner external {
  71.     uint256 i = 0;
  72.     uint256 toSend = value;
  73.     while (i < dests.length) {
  74.         sendInternally(dests[i] , toSend, value);
  75.         i++;
  76.     }
  77.   }  
  78.  
  79.   function sendInternally(address recipient, uint256 tokensToSend, uint256 valueToPresent) internal {
  80.     if(recipient == address(0)) return;
  81.  
  82.     if(tokensAvailable() >= tokensToSend) {
  83.       token.transfer(recipient, tokensToSend);
  84.       TransferredToken(recipient, valueToPresent);
  85.     } else {
  86.       FailedTransfer(recipient, valueToPresent);
  87.     }
  88.   }  
  89.  
  90.  
  91.   function tokensAvailable() constant returns (uint256) {
  92.     return token.balanceOf(this);
  93.   }
  94.  
  95.   function destroy() onlyOwner {
  96.     uint256 balance = tokensAvailable();
  97.     require (balance > 0);
  98.     token.transfer(owner, balance);
  99.     selfdestruct(owner);
  100.   }
  101. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top