how could I go about sending tokens to a couple of thousands of addresses without havinging to do it manually? It's an airdrop.
-
A contract might be able to take care of but in a way that might surprise. Can you be more specific? Are there particular accounts, specific amounts, or just a pile for the asking in even amounts for anyone with an ethereum address?– Rob HitchensCommented Oct 23, 2017 at 22:05
-
it will cost you some money, why not to make an ICO-like contract. people gets directly the tokens instead droping tks to a bunch of addresses.– Badr Bellaj ♦Commented Oct 23, 2017 at 22:58
-
It's a specific amount to be sent to many addresses. I can't do it manually because that would take a couple of days– ViniCommented Oct 24, 2017 at 6:18
-
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– RajeshCommented Nov 22, 2017 at 7:49
-
where to include the list of address in the code? how does the code read the list of address to which the tokens should be sent?– IGCGamersCommented Feb 9, 2018 at 13:52
3 Answers
OmiseGo just released their Airdropper contract that Vitalik purportedly wrote the original version of. It sends many values to many addresses.
It's fairly straightforward: you pass an array of addresses and an array of values and iterate through them sending the funds to each address.
contract Airdropper is Ownable {
function multisend(address _tokenAddr, address[] dests, uint256[] values)
onlyOwner
returns (uint256) {
uint256 i = 0;
while (i < dests.length) {
ERC20(_tokenAddr).transfer(dests[i], values[i]);
i += 1;
}
return(i);
}
}
You can do it with a contract in a few ways.
You could use a "pull/withdraw" pattern. Create a contract where users request to withdraw the airdropped tokens and you keep a balance of how many tokens a given address has withdrawn. You could also create a whitelist/blacklist of addresses to allow/disallow certain addresses to receive the tokens.
You can also do it the other way around. Create a contract where people signup by entering their address, and then when you decide so, you can call a function that iterates over the array of addresses and sends them the tokens. The problem with this approach is that is more prone to problems if the list is big enough that there's not enough gas to perform this transaction. You could code it to perform the airdrop in batches to prevent this problem. If it's just a few thousand addresses you should be fine, though.
-
-
How can I do pull/withdraw pattern for 7500 addresses? Commented Dec 17, 2021 at 7:16
You can automate sending tokens to multiple addresses using a script or a smart contract function. Here’s a basic approach using a smart contract in Solidity:
pragma solidity ^0.8.0;
import "IERC20.sol";
contract Airdrop {
function distributeTokens(address tokenAddress, address[] memory recipients, uint[] memory amounts) external {
require(recipients.length == amounts.length, "Arrays length mismatch");
IERC20 token = IERC20(tokenAddress);
for (uint i = 0; i < recipients.length; i++) {
token.transferFrom(msg.sender, recipients[i], amounts[i]);
}
}
}
This distributeTokens
function takes an ERC-20 token address (tokenAddress
), an array of recipient addresses (recipients
), and an array of corresponding token amounts (amounts
). It transfers tokens to each recipient in a single transaction.
Alternatively, consider using Off Grid Platform's Bulk Sender for a more streamlined approach to managing large-scale token distributions. You can explore more about it here: OGP Bulk Sender.