Solidity

本合約未實現所有功能,因此無法發布

  • January 26, 2019

在 Remix 上,執行此處建議的契約時 - https://www.youtube.com/watch?v=JHrQ3l2tT78 - 我收到錯誤消息“此契約未實現所有功能,因此無法發布。”

我看過其他文章說建構子需要列出參數,但我嘗試向“NewToken”添加參數但沒有成功。也許我添加了這些錯誤,但鑑於 tut 沒有任何內容,我想我可能做錯了其他事情。

感謝任何幫助。

pragma solidity ^0.4.11;

import './IERC20.sol';

/**
* @title Standard ERC20 token
*/
contract NewToken is IERC20 {

   uint public constant _totalSupply = 1000000;
   uint8 public constant _decimals = 3;
   string public constant _symbol = 'NTK';
   string public constant _name = 'NewToken';

   mapping(address => uint256) balances;
   mapping(address => mapping(address => uint256)) approved;


   function NewToken() public {
       balances[msg.sender] = _totalSupply;
   }

   function decimals() public constant returns (uint8 decimals) {
       return _decimals;
   }

   function totalSupply() public constant returns (uint256 totalSupply) {
       return _totalSupply;
   }

   function balanceOf(address _owner) public constant returns (uint256 balance) {
       return balances[_owner];
   }

   function transfer(address _to, uint256 _value) public returns (bool success) {
       require(
           balances[msg.sender] >= _value && _value > 0    
       );
       balances[msg.sender] -= _value;
       balances[_to] += _value;
       Transfer(msg.sender, _to, _value);
       return true;
   }

   function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
       require(
           approved[_from][msg.sender] >= _value && balances[_from] >= _value && _value > 0
       );
       balances[_from] -= _value;
       balances[_to] += _value;
       approved[_from][msg.sender] -= _value;
       Transfer(_from, _to, _value);
       return true;
   }

   function approve(address _spender, uint256 _value) public returns (bool success) {
       approved[msg.sender][_spender] = _value;
       Approval(msg.sender, _spender, _value);
       return true;
   }

   function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
       return approved[_owner][_spender];
   }

   event Transfer(address indexed _from, address indexed _to, uint256 _value);

   event Approval(address indexed _owner, address indexed _spender, uint256 _value);

}

IERC20.sol

pragma solidity ^0.4.11;

interface IERC20 {
   function decimals() public constant returns (uint8 decimals);
   function totalSupply() public constant returns (uint256 totalSupply);
   function balanceOf(address _owner) public constant returns (uint256 balance);
   function transfer(address _to, uint256 _value) public returns (bool success);
   function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
   function approve(address _spender, uint256 _value) public returns (bool success);
   function allowance(address _owner, address _spender) public constant returns (uint256 remaining);
   event Transfer(address indexed _from, address indexed _to, uint256 _value);
   event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}

我決定將您的程式碼載入到 Remix 中並親自查看,並且……沒問題。

可能問題在於對 Remix 或 Solidity 的熟悉程度。IERC20合約無法編譯,因為它只是描述了一堆函式簽名而沒有定義它們的作用。就是NewToken這樣。主要內容,您可以NewToken按預期編譯、創建和部署。混音讓你選擇,但只有一個選擇會成功。

還。有一個我還不太習慣的全新 Remix。圖片使用的是https://yann300.github.io/remix04上的舊混音。我不排除您的問題可能源於 Remix 版本的新鮮度。

這是在 Remix 中展示它的工作。

在此處輸入圖像描述

希望能幫助到你。

引用自:https://ethereum.stackexchange.com/questions/27664