2

我已经成功地使用 Frontier 网站上的“操作方法”创建了一个注册的以太坊“令牌”。我打算继续签订众包合同,为能够在世界上做一些好事的筹款活动筹集资金,但稍后会详细介绍。代币创建文本包含改进我的新代币功能的建议:例如,您可以通过创建一个交易来奖励发现当前区块的人来奖励以太坊矿工:

mapping (uint => address) miningReward;
function claimMiningReward() {
if (miningReward[block.number] == 0) {
 coinBalanceOf[block.coinbase] += 1;
 miningReward[block.number] = block.coinbase;
  }
}

只需将此代码粘贴到我的合同中自然会产生错误消息。

问: 我需要调整、输入、更改什么,才能用我的一种代币奖励未成年人?对于每一个开采的新区块。谢谢你。

4

2 回答 2

0

您可以将代码片段复制并粘贴到token合同中。它看起来像这样:

contract token { 
    mapping (address => uint) public coinBalanceOf;
    event CoinTransfer(address sender, address receiver, uint amount);

    /* Initializes contract with initial supply tokens to the creator of the contract */
    function token(uint supply) {
        if (supply == 0) supply = 10000;
            coinBalanceOf[msg.sender] = supply;
    }

    /* Very simple trade function */
    function sendCoin(address receiver, uint amount) returns(bool sufficient) {
        if (coinBalanceOf[msg.sender] < amount) return false;
        coinBalanceOf[msg.sender] -= amount;
        coinBalanceOf[receiver] += amount;
        CoinTransfer(msg.sender, receiver, amount);
        return true;
    }

    mapping (uint => address) miningReward;

    /* Reward Ethereum block miner with a token */
    function claimMiningReward() {
        if (miningReward[block.number] == 0) {
            coinBalanceOf[block.coinbase] += 1;
            miningReward[block.number] = block.coinbase;
        }
    }
}
于 2016-01-29T19:59:51.237 回答
0

我不知道你有没有想到这一点。遇到相同问题的其他人请尝试以下代码段:

contract MyToken { 
    /* Public variables of the token */
    string public name;
    string public symbol;
    uint8 public decimals;

    /* This creates an array with all balances */
    mapping (address => uint256) public balanceOf;

    /* This generates a public event on the blockchain that will notify clients */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /* Initializes contract with initial supply tokens to the creator of the contract */
    function MyToken(uint256 _supply, string _name, string _symbol, uint8 _decimals) {
        /* if supply not given then generate 1 million of the smallest unit of the token */
        if (_supply == 0) _supply = 1000000;

        /* Unless you add other functions these variables will never change */
        balanceOf[msg.sender] = _supply;
        name = _name;     
        symbol = _symbol;

        /* If you want a divisible token then add the amount of decimals the base unit has  */
        decimals = _decimals;
    }

    /* Send coins */
    function transfer(address _to, uint256 _value) {
        /* if the sender doenst have enough balance then stop */
        if (balanceOf[msg.sender] < _value) throw;
        if (balanceOf[_to] + _value < balanceOf[_to]) throw;

        /* Add and subtract new balances */
        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;

        /* Notifiy anyone listening that this transfer took place */
        Transfer(msg.sender, _to, _value);
    }
}            

然后添加您的代码以奖励矿工,但将“coinBalanceOf”更改为“balanceOf”,如下所示:

mapping (uint => address) miningReward;

function claimMiningReward() {
    if (miningReward[block.number] == 0) {
        balanceOf[block.coinbase] += 1;
        miningReward[block.number] = block.coinbase;
    }
}

所以你的最终合同看起来像这样:

contract MyToken { 
    /* Public variables of the token */
    string public name;
    string public symbol;
    uint8 public decimals;

    /* This creates an array with all balances */
    mapping (address => uint256) public balanceOf;

    /* This generates a public event on the blockchain that will notify clients */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /* Initializes contract with initial supply tokens to the creator of the contract */
    function MyToken(uint256 _supply, string _name, string _symbol, uint8 _decimals) {
        /* if supply not given then generate 1 million of the smallest unit of the token */
        if (_supply == 0) _supply = 1000000;

        /* Unless you add other functions these variables will never change */
        balanceOf[msg.sender] = _supply;
        name = _name;     
        symbol = _symbol;

        /* If you want a divisible token then add the amount of decimals the base unit has  */
        decimals = _decimals;
    }

    /* Send coins */
    function transfer(address _to, uint256 _value) {
        /* if the sender doenst have enough balance then stop */
        if (balanceOf[msg.sender] < _value) throw;
        if (balanceOf[_to] + _value < balanceOf[_to]) throw;

        /* Add and subtract new balances */
        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;

        /* Notifiy anyone listening that this transfer took place */
        Transfer(msg.sender, _to, _value);
    }

    mapping (uint => address) miningReward;

    function claimMiningReward() {
        if (miningReward[block.number] == 0) {
            balanceOf[block.coinbase] += 1;
            miningReward[block.number] = block.coinbase;
        }
    }

} 
于 2016-02-17T00:42:57.200 回答