Can I execute distributions in ERC20 tokens on a later stage?

0 votes

I need to implement Distribute function in ERC20 token code which will send equal amount of the tokens on an array of addresses when executed. Below is the source code that I will use for that. Of course I will change the variables for my token:

https://pastebin.com/wAe9a1EV

Is the Distribute function that I add at the end of the contract suitable and does not interfere with the rest of the source code? Can I execute distributions on a later stage through Myetherwallet or Mist with that function if I deploy the contract with that function on the blockchain?

 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);
 }
}
Nov 2, 2018 in Blockchain by Perry
• 17,090 points
32 views

1 answer to this question.

0 votes

It is best to have a claim function and have users call the function to get their tokens as opposed to having an owner try to distribute them. The amount of gas the owner has to pay to distribute the tokens would be breathtaking.

Possibly giving out tokens as soon as a user has sent ether to the contract is better solution.

Make sure you add some sanity checks to that function, you should do some basic checks to avoid user error.

e.g

require(_value > 0);
require(balances[owner] >= (_value * addresses.length));

// In your loop
require(addresses[i] != 0x0);
answered Nov 2, 2018 by Prerna
• 1,940 points

Related Questions In Blockchain

+1 vote
2 answers
+1 vote
2 answers

Can I include real world data in a smart contract? If so, how?

You cant access/embed real world data using ...READ MORE

answered Jul 17, 2018 in Blockchain by sapan
79 views
+1 vote
1 answer

How can I initiate a transaction on ethereum private network using mobile device?

There is no android wallet to connect ...READ MORE

answered Apr 18, 2018 in Blockchain by Shashank
• 10,350 points
65 views
0 votes
1 answer

How can i create a simple P2P network on a blockchain?

To develop your own cryptocurrency, you need ...READ MORE

answered Apr 20, 2018 in Blockchain by Christine
• 15,810 points
229 views
+1 vote
1 answer

Can I mine a specific transaction on ethereum?

On a public ethereum network it is ...READ MORE

answered Apr 23, 2018 in Blockchain by Shashank
• 10,350 points
31 views
0 votes
1 answer

How can I deploy a HelloWorld contract on my testrpc network?

The problem lies in the command: truffle migrate Your truffle migrate command ...READ MORE

answered Apr 27, 2018 in Blockchain by Perry
• 17,090 points

edited Aug 10, 2018 by Omkar 541 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,810 points
185 views
0 votes
1 answer
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 68,180 points
116 views