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
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
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.
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);
}
}
I am trying to distribute fund here on a single transaction. Any help will be appreciated. Thanks
– Deepak Bhavsar Dec 17 '21 at 05:55This article gives a good solution.
airdropTokens(address[] addresses, value) function in your token contract that transfers value tokens to each address with a for loop.The article gives more detail but basically that's all you need.
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