2

I have this smart contract to send tokens to multiple addresses:

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]);
    }
  }
}

enter image description here

When I access the function "Drop" via MyEtherWallet, I don't know how to insert the addresses in the field "recipients".

I've tried this but none of them work:

0x0000000000000000000000000000000000000001, 0x0000000000000000000000000000000000000002, 0x0000000000000000000000000000000000000003

0x0000000000000000000000000000000000000001 0x0000000000000000000000000000000000000002 0x0000000000000000000000000000000000000003

['0x0000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000002', '0x0000000000000000000000000000000000000003']

["0x0000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000003"]

I can only execute the first one, but it says "Bad Instruction" or "Fail". In the other options I press the button "Write" but nothing happens

2
  • 2
    Both recipients and values have to be arrays of the same size. Try recipients = ["0x1234..", "0x1234..", "0x1234.."], values = [667, 668, 669]
    – Ismael
    Commented Feb 26, 2018 at 14:53
  • Thank you!! I didn't know that about values... It worked with recipients = 0x1234, 0x1234, 0x1234..... and values = 100, 101, 102.... Without "[]" and without " "" " Commented Feb 26, 2018 at 15:15

2 Answers 2

1

Both recipients and values have to be arrays of the same size. Try recipients = 0x1234.., 0x1234.., 0x1234.., values = 667, 668, 669. Thanks to Ismael for the answer

0

This is not an answer to your question but just a heads up, it is not recommended to iterate over transfers but to create a withdraw method. I recommend that you also look at re-entrancy attacks while you're at it and maybe implement some modifiers for safety.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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