简体   繁体   中英

Distribution function in ERC20 token which can be executed on a later stage?

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);
 }
}

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 hser 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.

eg

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

// In your loop
require(addresses[i] != 0x0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM