简体   繁体   English

ERC20令牌中的分配功能可以在以后执行吗?

[英]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. 我需要在ERC20令牌代码中实现Distribute函数,该函数在执行时将在地址数组上发送相等数量的令牌。 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 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? 我在合同末尾添加的Distribute函数是否合适并且不会干扰其余的源代码? 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? 如果我将具有该功能的合同部署在区块链上,可以在以后通过Myetherwallet或Mist使用该功能执行分发吗?

 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. 最好有一个Claim函数,并让用户调用该函数以获取其令牌,而不是让所有者尝试分发它们。 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. 最好在hser将以太币发送给合约后立即发出令牌。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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