0

I want to distribute tokens to a few thousand addresses at once. I want to know, how can I do this? My token contract is already deployed so I want to make a new contract in solidity that can interact with my deployed contract. Can someone help?

I found this code from another post on this site that I assume I can use in the new contract:

    function distributeToken(address[] addresses, uint256 _value) onlyOwner {
     for (uint i = 0; i < addresses.length; i++) {
         balances[owner] -= _value;
         balances[addresses[i]] += _value;
         Transfer(owner, addresses[i], _value);
     }
}

I am writing this contract in remix so I do not have truffle or any advance coding systems. Hope someone can help.

  • Check this ethereum.stackexchange.com/a/31332/20357 – Rajesh Mar 19 '18 at 5:08
  • Ok, so from what I read, I deploy the contract from the above link, send the amount of tokens I want to airdrop from my token contract to the airdrop contract and then I can sent tokens to multiple people? 1. What the exact format to send tokens via calling the function in solidity? 2. How many addresses can I send to at once and how do I specify the amount of tokens each address should receive? – RamenCoin Mar 19 '18 at 6:21
  • @rajesh I am getting this error when using sendTokensSingleValue function transact to AirDrop.sendTokensSingleValue errored: Error encoding arguments: Error: Argument is not a number – RamenCoin Mar 19 '18 at 6:55
  • 1
    The arguments must be passed like ["0xasdf..","0xawer.."],"200" – Rajesh Mar 19 '18 at 8:22
  • Ok, is there a way to make the contract send to people if they send "0" ETH to the contract but of course provide gas for the token to be delivered to them? Also is it possible to make sure the same address can not get it? – RamenCoin Mar 19 '18 at 23:52
0

Answer edit:

You need to add the 18 "0" so if you want to give 100 token, 100000000000000000000. Feel free to use any math calculation to make it more readable. This value should be uint256

Understand that using this code, addresses array you will supply will need to be smaller than about 100 or 150 addresses at a time because of the gaz limit. So this is not a liable nor viable option if you have lots of airdrop destination to do, it will be long and costly.

I would myself do a function like a bounty, where user itself can query it, pay the fee amd get a predetermined amount of token one time or in a pre determined timelapse.

Also if your contract is already published on main net and used, you cannot edit it, and your code require to be put in the same contract of the token or you would need to create a new contract just for the airdrop and callimg externally the token contract which result in more gaz fee for you.

See this post made by me : Trying to input big array (500+) of addresses as argument

See this working example of airdrop, notice the maximum of destinations is 150 or less addresses.

https://github.com/indorseio/airdrop/blob/master/indorser.sol

| improve this answer | |
  • @rajesh I have a code to post but stackexchange says the characters are too long so I posted it on pastebin: pastebin.com/AByDLNB5 This is a new airdrop code I created allows for people to send 0 ETH to the contract to get the set amount of Tokens however, the receiver is getting 0.0000000000000001 instead of 100. I need someone to help me fix this so they can get 100 tokens. Also, I need to add the destroy function to my contract to make sure i can send tokens back to my contract if i destroy the airdrop contract. Thank you so much – RamenCoin Mar 30 '18 at 2:54
  • Is your token have 18 decimal? Also considere marking my answer as correct if I fix that :) – btc4cash Mar 30 '18 at 2:56
  • Yes my token is 18 decimals. So what do i need to add to fix and which answer do i need to mark correct? – RamenCoin Mar 30 '18 at 2:59
  • I just edited my answer. You just need to edit the token amount and include its decimal – btc4cash Mar 30 '18 at 3:50
0

Since you asked about burn the tokens, use the below code. You can optionally pass the parameter of the address from where it has to be burnt too. This is picked from here

/**
     * Destroy tokens
     *
     * Remove `_value` tokens from the system irreversibly
     *
     * @param _value the amount of money to burn
     */
    function burn(uint256 _value) public returns (bool success) {
        require(balanceOf[msg.sender] >= _value);   // Check if the sender has enough
        balanceOf[msg.sender] -= _value;            // Subtract from the sender
        totalSupply -= _value;                      // Updates totalSupply
        Burn(msg.sender, _value);
        return true;
    }
| improve this answer | |
  • Thank both of you for responding! @rajesh how can I use the initial contract you provided a way for users to send ETH to get a set amount of tokens for the amount of ETH sent. I need it to interact with a token contract that has already been deployed. Is it possible to alter some code in the airdrop contract you provided to do so? If so, can you provide the code. Thank you – RamenCoin Mar 26 '18 at 13:04
  • Check out here (ethereum.stackexchange.com/a/43942/20357), you may slightly need to add price based calculations to match your needs. And ensure the deployed contract (from the above link) has enough tokens in it. – Rajesh Mar 27 '18 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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