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,100 points
634 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,960 points

Related Questions In Blockchain

+1 vote
2 answers

Hyperledger - Can I have some instances on one network while on a Virtual Box?

Yes, you can connect multiple instances to ...READ MORE

answered Aug 1, 2018 in Blockchain by Omkar
• 69,210 points
709 views
+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 18, 2018 in Blockchain by sapan
893 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,400 points
704 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,790 points
1,736 views
+1 vote
1 answer

Can I mine a specific transaction on ethereum?

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

answered Apr 24, 2018 in Blockchain by Shashank
• 10,400 points

edited Oct 6, 2021 by Sarfaraz 1,256 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,100 points

edited Aug 10, 2018 by Omkar 2,472 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,790 points
1,697 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,235 views
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
• 69,210 points
1,250 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP