我有一个项目,我打算通过ERC20令牌支付给我的用户。
我们打算开发一个人工智能学习机器,将收集信息,从用户的活动,根据他们需要完成的任务,在我们的平台上获得报酬。我们希望人工智能软件通过与所需信息的更新来与智能契约交互。一旦smart合同收到了这样的信息,它就会根据AI提供的报告,提取所需的令牌,并在他们的each钱包中奖励每个成员。
我想知道这是否可能,以及如何做到这一点。
我们将非常感谢您的贡献。
谢谢
发布于 2018-03-23 22:32:13
一个帐户地址‘ERC 20余额只是简单的任何balanceOf
功能说明它是。
当您可以定义函数时,您可以决定每个帐户的余额是什么。
这意味着你可以做各种古怪的事情,无论你如何决定合同的运作。
除了所需函数名的规范之外,ERC20令牌没有什么特殊或神秘的地方。
对于大多数合同来说,铸造硬币只不过是在一个变量中添加一个数字,而不是从另一个变量中减去一个数字。相反,燃烧硬币是从一个变量中减去一个数字,而不是将它添加到另一个变量中。通常,处理余额的变量是帐户地址和余额之间的映射。
/// @notice Will cause a certain `_value` of coins minted for `_to`.
/// @param _to The address that will receive the coin.
/// @param _value The amount of coin they will receive.
function mint(address _to, uint _value) public {
require(msg.sender == owner); // assuming you have a contract owner
balances[_to] += value;
supply += value;
require(balances[_to] >= value && supply >= value); // overflow checks
emit Transfer(address(0), _to, _value);
}
但是这并不是一成不变的,您的合同可以在balanceOf
函数中执行您可能想到的任何事情。
要明确地回答您的问题,是的,您可以有一个只有您可以调用的函数,它将根据用户在契约外部的操作创建新的令牌。
请注意,每次执行函数以创建新的令牌时,调用定义的mint()
函数将花费您(或某人)的精力。
通常,为了缓解这一问题,人们会在合同中加入“批处理”或“空投”功能,以便在一个呼叫中进行多个更新,从而节省汽油。
/// @notice Will cause a certain `_value` of coins minted for `_to`.
/// @param _to The address that will receive the coin.
/// @param _value The amount of coin they will receive.
function mint(address _to, uint _value) public {
require(msg.sender == owner); // assuming you have a contract owner
mintToken(_to, _value);
}
/// @notice Will allow multiple minting within a single call to save gas.
/// @param _to_list A list of addresses to mint for.
/// @param _values The list of values for each respective `_to` address.
function airdropMinting([]address _to_list, []uint _values) public {
require(msg.sender == owner); // assuming you have a contract owner
require(_to_list.length == _values.length);
for (uint i = 0; i < _to_list.length; i++) {
mintToken(_to_list[i], _values[i]);
}
}
/// Internal method shared by `mint()` and `airdropMinting()`.
function mintToken(address _to, uint _value) internal {
balances[_to] += value;
supply += value;
require(balances[_to] >= value && supply >= value); // overflow checks
emit Transfer(address(0), _to, _value);
}
在本例中,您可以每天调用一次airdropMinting函数(或您觉得足够的时间间隔),其中包含一个造币项目列表,它将依次执行每个项目,每增加一项节省约21,000个气体。
注意:我们已经重新定义了mint()来调用内部造币的函数,虽然我们可以从mint()
内部调用原始的mintToken()
函数,但是从内部调用外部函数需要额外的气体成本。
注2:一次可以制造的物品的数量是有限制的,这是基于800万气体的全球气体限制。
https://ethereum.stackexchange.com/questions/43687
复制相似问题