0

I have this code to send a multi-transaction of token in a short airdrop

pragma solidity ^0.4.18;
contract ERC20 {
function transfer(address _recipient, uint256 _value) public returns (bool 
       success);
}

contract Airdrop {
function drop(ERC20 token, address[] recipients, uint256[] values) public {
  for (uint256 i = 0; i < recipients.length; i++) {
    token.transfer(recipients[i], values[i]);
  }
 }
}

I've deployed the contract but while it was successful, no token was received by the recipient. Do you see any errors here?

  • After deploying the contract, you must call the function drop with the parameters to have the tokes dropped. Did you do that? provide txn hash for people to check and get back to you – Rajesh Jun 17 '18 at 15:59
  • @Rajesh I call the function drop this is the txn 0x993e9ad6fa4fb142c21ea1b6a010ff214ee09470c6dc8f80fe7c664cc8c47ff5 success but there are no Token send in the address I provide I set the token address with the token contract address and the recipient to the recipient and the amount to amount I want but success but not receive – ArchDevOps Jun 18 '18 at 11:09
  • Can you also explain how did you execute/call the function? Did you use Remix? Can you also provide how did you pass the parameters? If its remix, you enclose the recipients and values within square bracket, items separated by the comma, surrounded by double quotes. – Rajesh Jun 18 '18 at 13:26
  • I create a new contract for this do I need to deploy this airdrop function in the same contract where I create the token? @Rajesh – ArchDevOps Jun 19 '18 at 15:30
  • Not required. It can be in a separate contract too. If you pass the parameters incorrectly you would get nothing. So, you will have to check the parameters passing again. – Rajesh Jun 20 '18 at 0:12
0

This should work.

/**
        * @dev Transfer the specified amounts of tokens to the specified addresses.
        * @dev Be aware that there is no check for duplicate recipients.
        *
        * @param _toAddresses Receiver addresses.
        * @param _amounts Amounts of tokens that will be transferred.
        */
        function drop(address[] _toAddresses, uint256[] _amounts) public {
            /* Ensures _toAddresses array is less than or equal to 255 */
            require(_toAddresses.length <= 255);
            /* Ensures _toAddress and _amounts have the same number of entries. */
            require(_toAddresses.length == _amounts.length);

            for (uint8 i = 0; i < _toAddresses.length; i++) {
                transfer(_toAddresses[i], _amounts[i]);
            }
        }

Edit: Should be inserted into a token contract.

0

This might sound stupid... But did you send the tokens to the air drop contract?

The airdrop co tract will only be able to send the tokens that it (the contract address) holds.

  • yes I solve it now – ArchDevOps Jul 13 '18 at 15:44

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.