创建以太坊代币作为挖矿奖励

  • 本文关键字:创建 token mining ethereum
  • 更新时间 :
  • 英文 :


我主要使用Frontier网站上的"如何"创建了一个注册的以太坊"代币"。我打算继续进行众包合同,为一场能够在世界上做一些好事的筹款活动筹集资金,但稍后会有更多内容。令牌创建文本包括以下建议,用于改进我的新令牌的功能:例如,你可以通过创建一个交易来奖励以太坊矿工,该交易将奖励找到当前区块的人:

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

简单地将这些代码粘贴到我的合同中自然会产生错误消息。

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

您可以将代码片段复制并粘贴到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;
        }
    }
}

我不知道你是否已经想通了。其他有同样问题的人可以尝试以下片段:

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

最新更新