0

I have to create a contract to distribute 1000 tokens to 1000 addresses (1 token each). I have no idea how to do this. Can someone please advise?

I know I must create a contract, but what code should I use? Is it possible to specify a gas limit for each transaction?

Also, what parameters do I need to configure for this to work when actually sending?

Apologies for my greenness

3

you are almost asking someone to write the contract for you. You should post what code you have tried so far, what errors you are getting and ask for some particular pointers.

Nevertheless, here's some code that should get you on the right track. I'm assuming you are the owner of these tokens. Notice that the only way for this contract to transfer the tokens is for it to use the transferFrom function from the ERC20 tokens.

That means that before using the code below you will have to call the approve function from your account in order to allow this contract to use your tokens.

pragma solidity ^0.4.18;

contract ERC20 {
    function transferFrom(address _from, address _to, uint _value) returns (bool success);
}

contract TokenAirdrop {

    function sendTokens(address[] beneficiaries) public {
        ERC20 token = ERC20(OXO...); //Token address
        for (uint8 i = 0; i< beneficiaries.length; i++){
            address beneficiary = beneficiaries[i];
            token.transferFrom(OWNER_OF_TOKENS, beneficiary, 1);
        }

    }
}
| improve this answer | |
  • Agree! your snipped is working! – user19060 Nov 14 '17 at 14:21
  • Thank you for this. I;ve reokaced OXO... with the original token address, it gave me an error for 0.4.18 so I changed to 0.4.16 but now its telling me: Undeclared identifier. token.transferFrom(OWNER_OF_TOKENS, beneficiary, 1); ^-------------^ for this line token.transferFrom(OWNER_OF_TOKENS, beneficiary, 1); – Matthew Hughes Nov 14 '17 at 17:22
  • OWNER_OF_TOKENS should be replaced by the address who owns the tokens and previously approved the token transfer by setting the allowance – pabloruiz55 Nov 14 '17 at 19:45
  • when i deploy this contract by address owner token contract , how can i send tokens to joined airdrop once time? – TahaBA Nov 14 '17 at 22:49
  • it's insane how every airdrop tutorial forgets to mention that you have to approve contract before you are able to send on behalf of contract(which is logical, but for beginner there is no way to know). – sensei May 21 '18 at 7:22
0

Make a array with size 100 and allow the contract to send the Tokens to each address when triggered.

You can take a look at the ready and implemented contract Here :

https://github.com/KyberNetwork/airdrop/blob/master/contracts/KyberAirDrop.sol

| improve this answer | |
  • do you can explain this code and where is the way to add airdrop addresses – TahaBA Nov 15 '17 at 0:36

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