【问题标题】:creating Ethereum tokens as mining rewards创建以太坊代币作为挖矿奖励
【发布时间】:2016-03-21 22:01:42
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: token mining ethereum


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      我不知道你是否想通了。有同样问题的其他人尝试以下 sn-p:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-11
        • 1970-01-01
        • 2021-10-17
        • 2016-02-28
        • 1970-01-01
        • 2022-08-16
        相关资源
        最近更新 更多