7

I am trying to host an airdrop but sending the tokens individually to thousands of people would take forever. Is there a way to do it in one transaction with multiple recipients.

If so, could you please provide me with some code.

Thanks

Dylan
  • 71
  • 1
  • 2
  • Am adding comment here to help people trying to do via mist after created their token to refer here https://ethereum.stackexchange.com/a/31332/20357 – Rajesh Nov 22 '17 at 07:49
  • This changes a lot if you mean sending ether or sending ERC20 tokens. – Davide C Jan 27 '18 at 10:58

4 Answers4

5

You are quite discouraged to use the sending pattern, especially if you want to send/transfer funds (ether/tokens etc.) to thousands of people as you mentioned. This way you can easily get self-pwned by running out of gas, for instance. Have a look at this (and the next slide). Another problem with the sending pattern is that you should have in mind that there is no guarantee that the .send() (or .transfer()) function will succeed. You should be always prepared for such edge cases in your smart contract code, i.e. bail out, work arounds etc. Perfect example for this is the KingOfTheEtherThrone 'hack'.

Therefore you should use the withdrawal pattern, where your users/partners will withdraw their funds, you should not get involved sending funds around. The withdrawal pattern is greatly explained here.

  • 2
    This answer applies to send( ) of ether, the question was about sending tokens, which is not about sending anything actually but invoking transfer() in a ERC20 contract – Davide C Jan 27 '18 at 10:56
  • Made some edit to reflect your just comment! Thanks! – István András Seres Sep 07 '18 at 21:58
  • there is a lot of things that can go wrong with this approach. For example, if a recipient is smart contract that cannot receive Ether, the JavaScript side has to dry-run and pre-validate all addresses. I'd recommend trying https://multisender.app because it does all the heavy lifting for you. – rstormsf Apr 29 '21 at 21:13
1

On chain you would have to use a contract with something like a sendToMany function:

function sendToMany(address[] recipients) {
for(uint i = 0; i< recipients.length; i++){
     i.send(msg.value/recipients.length);
     }
}
CBobRobison
  • 1,245
  • 12
  • 20
  • Be sure to calculate gas ahead of time so you don't exceed the gas limit. Source: https://www.reddit.com/r/ethereum/comments/4fija2/is_this_true_ethereum_does_not_allow_multiple/ – CBobRobison Oct 10 '17 at 05:50
  • How to send token to 7000 address in single transaction? this will give out of gas error . Even if i want user to withdraw their fund I have to store their fund in contract which will also run out of gas if i want to store for 7000 address?

    I am trying to distribute fund here on a single transaction. Any help will be appreciated. Thanks

    – Deepak Bhavsar Dec 17 '21 at 05:55
1

This article gives a good solution.

  • Have all your addesses in a CSV file (remove blanks or erroneous addresses first)
  • Make an airdropTokens(address[] addresses, value) function in your token contract that transfers value tokens to each address with a for loop.
  • Write a scipt to call the function the entries of your CSV file. The article recommends to slice your data, calling the function by batches of 80 (in his example). Calling a function with a very large array might be inefficient.

The article gives more detail but basically that's all you need.

Teleporting Goat
  • 1,516
  • 1
  • 13
  • 33
0

You can use this open-source tool - http://bulktokensending.online It allows generating ETH addresses also. The source is here https://github.com/bulktokensending/bulktokensending

ma ster
  • 59
  • 1