0

I used Mist Wallet (Rinkeby Network) to try this.

Have created a contract same as given here. For the sake of quick understanding, am pasting it below. I created this contract from the same owner that created the token.

pragma solidity ^0.4.16;

/**
 * @title Ownable
 * @dev The Ownable contract has an owner address, and provides basic authorization control 
 * functions, this simplifies the implementation of "user permissions". 
 */
contract Ownable {
  address public owner;

  function Ownable() {
    owner = msg.sender;
  }

  modifier onlyOwner() {
    if (msg.sender != owner) {
      revert();
    }
    _;
  }

  function transferOwnership(address newOwner) onlyOwner {
    if (newOwner != address(0)) {
      owner = newOwner;
    }
  }

}

contract ERC20Basic {
  uint public totalSupply;
  function balanceOf(address who) constant returns (uint);
  function transfer(address to, uint value);
  event Transfer(address indexed from, address indexed to, uint value);
}

contract ERC20 is ERC20Basic {
  function allowance(address owner, address spender) constant returns (uint);
  function transferFrom(address from, address to, uint value);
  function approve(address spender, uint value);
  event Approval(address indexed owner, address indexed spender, uint value);
}

contract Airdropper is Ownable {

    function multisend(address _tokenAddr, address[] dests, uint256[] values)
    onlyOwner
    returns (uint256) {
        uint256 i = 0;
        while (i < dests.length) {
           ERC20(_tokenAddr).transfer(dests[i], values[i]);
           i += 1;
        }
        return(i);
    }
}

Have executed the Multisend function as per the below image.

enter image description here

The function gets executed, but none of the address seems to have received the tokens. The transaction hash is 0xeb759ea8f6c923874adfc6961555733b36982f5d770dd24bf85456b534d2e2f9

What am I missing? Any help is highly appreciated.

3

This answer is suitable for those that created their tokens before, and want to add airdrop functionality to the token, and willing to execute the drop via Mist. It may work other means too but not tested.

Don't know why the above method (as asked in the question) didn't work. However, the below one worked for me. Am posting it as the answer so that it would be helpful for people with similar problem. This one worked in rinkeby to max 174 array items that consumed 3991732 gas.

Note

  1. The owner of the token contract that holds the token must send tokens to this contract address for it to function.

  2. Replace the address of your token in the constructor

pragma solidity ^0.4.16;

contract Ownable {

  address public owner;

  function Ownable() {
    owner = msg.sender;
  }

  modifier onlyOwner() {
    require(msg.sender == owner);
    _;
  }

  function transferOwnership(address newOwner) onlyOwner {
    require(newOwner != address(0));
    owner = newOwner;
  }
}

interface Token {
  function transfer(address _to, uint256 _value) returns (bool);
  function balanceOf(address _owner) constant returns (uint256 balance);
}

contract AirDrop is Ownable {

  Token token;

  event TransferredToken(address indexed to, uint256 value);
  event FailedTransfer(address indexed to, uint256 value);

  modifier whenDropIsActive() {
    assert(isActive());

    _;
  }

  function AirDrop () {
      address _tokenAddr = 0x; //here pass address of your token
      token = Token(_tokenAddr);
  }

  function isActive() constant returns (bool) {
    return (
        tokensAvailable() > 0 // Tokens must be available to send
    );
  }
  //below function can be used when you want to send every recipeint with different number of tokens
  function sendTokens(address[] dests, uint256[] values) whenDropIsActive onlyOwner external {
    uint256 i = 0;
    while (i < dests.length) {
        uint256 toSend = values[i] * 10**18;
        sendInternally(dests[i] , toSend, values[i]);
        i++;
    }
  }

  // this function can be used when you want to send same number of tokens to all the recipients
  function sendTokensSingleValue(address[] dests, uint256 value) whenDropIsActive onlyOwner external {
    uint256 i = 0;
    uint256 toSend = value * 10**18;
    while (i < dests.length) {
        sendInternally(dests[i] , toSend, value);
        i++;
    }
  }  

  function sendInternally(address recipient, uint256 tokensToSend, uint256 valueToPresent) internal {
    if(recipient == address(0)) return;

    if(tokensAvailable() >= tokensToSend) {
      token.transfer(recipient, tokensToSend);
      TransferredToken(recipient, valueToPresent);
    } else {
      FailedTransfer(recipient, valueToPresent); 
    }
  }   


  function tokensAvailable() constant returns (uint256) {
    return token.balanceOf(this);
  }

  function destroy() onlyOwner {
    uint256 balance = tokensAvailable();
    require (balance > 0);
    token.transfer(owner, balance);
    selfdestruct(owner);
  }
}
  • don't know how you was able to implement this, i am still getting error on array line when i input addresses. – user19060 Nov 29 '17 at 8:06
  • For example i have to send tokens to addresses A, B , C with amount 2 , 4 , 8 what code you have written does not work, please explain. – user19060 Nov 29 '17 at 8:07
  • Use the sendTokens that will accept values like ["A","B","C"],[2,4,8] – Rajesh Nov 29 '17 at 9:24
  • Please look at this thread, still i am unable to accomplish what you are saying. ethereum.stackexchange.com/questions/31971/… – user19060 Nov 29 '17 at 10:28
  • In the remix functions, you will have to send like how I posted above, I was successfully able to send to my recipients like that, also seems you are passing incorrect integer value as per your image. – Rajesh Nov 29 '17 at 12:05
0

I think you need to put the addresses in double-quotes

"0xaa..","0xbb.."

If you look at the input data at the bottom of your linked transaction on etherscan, you will see that the input data contains "64", "c8" and so on, which are your values in hex, but the addresses are missing.

Update: Sorry, it seems this might be an ui bug in Mist, see this issue (still open): https://github.com/ethereum/mist/issues/3054 - according to the reply there, it should work with quotes, but apparently does not.

  • If I enclose them with double quotes, the mist wallet warns the transaction will fail and all the gas will be consumed. I tried without any quotes, and single quotes, but still unable to see the tokens on recipient's address nor or the transaction hash overview. – Rajesh Nov 20 '17 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.