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

2
  • Am adding comment here to help people trying to do via mist after created their token to refer here ethereum.stackexchange.com/a/31332/20357
    – Rajesh
    Commented Nov 22, 2017 at 7:49
  • This changes a lot if you mean sending ether or sending ERC20 tokens.
    – Davide C
    Commented Jan 27, 2018 at 10:58

4 Answers 4

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.

3
  • 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
    Commented Jan 27, 2018 at 10:56
  • Made some edit to reflect your just comment! Thanks! Commented Sep 7, 2018 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 multisender.app because it does all the heavy lifting for you.
    – rstormsf
    Commented Apr 29, 2021 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);
     }
}
2
  • Be sure to calculate gas ahead of time so you don't exceed the gas limit. Source: reddit.com/r/ethereum/comments/4fija2/… Commented Oct 10, 2017 at 5: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 Commented Dec 17, 2021 at 5: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.

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

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