Mist

為什麼我的自定義令牌顯示為 0?

  • June 23, 2018

我通過測試網上的合約創建了一個普通的自定義代幣,並向它鑄造了 10,000 個硬幣,我能夠成功地將代幣發送到不同地址的錢包合約。但是,當我嘗試使用該Watch Token功能並粘貼合約地址時,餘額始終為零,儘管表單會自動載入其他合約變數。

圖示旁邊的數字不應該顯示與主賬戶地址關聯的自定義代幣數量嗎?

我在 ropsten 測試網上使用 Mist 0.8.10。

自定義令牌 契約細節

我的契約很簡單:

pragma solidity ^0.4.11;

contract PractCoin {

   mapping (address => uint256) public monies;
   address public owner;
   uint public totalCoins;
   uint public initialSupply;
   string public name;
   uint8 decimalPlaces;

   function PractCoin(uint _totalCoins, uint _initialSupply, string _name, uint8 _decimalPlaces){
       owner = msg.sender;
       totalCoins = _totalCoins;
       initialSupply = _initialSupply;
       monies[owner] = initialSupply;
       name = _name;
       decimalPlaces = _decimalPlaces;
   }

   function sendCoins(address _to, uint _amount){
       if (monies[msg.sender] < _amount || 
           msg.sender == _to || 
           monies[_to] + _amount < _amount) throw;
       monies[msg.sender] -= _amount;
       monies[_to] += _amount;
       CoinTransfer(_amount, _to, msg.sender);
   }

   function destroyContract(){
       if (msg.sender == owner ) selfdestruct(owner);
       ContractDestroyed("Contract Destroyed!");

   }

   event CoinTransfer(uint _amount, address indexed _to, address indexed _from);
   event ContractDestroyed(string _message);
}

您的合約不符合ERC20。保留 ERC20 標準非常重要,這意味著保持所有名稱相同。請參閱此定義契約。根據 ERC20,Mist 應該尋找以下屬性:

uint public supply;
string public name;
uint8 public decimals;
string public symbol;
string public version;

您還應該包括以下所有功能以符合 ERC20:

function totalSupply() constant returns (uint) {
 return supply;
}

function balanceOf( address who ) constant returns (uint) {
 return balances[who];
}

function transfer( address to, uint value) returns (bool) {
 balances[msg.sender] = safeSub(balances[msg.sender], value);
 balances[to] = safeAdd(balances[to], value);
 Transfer( msg.sender, to, value );
 return true;
}

function transferFrom( address from, address to, uint value) returns (bool) {
 approvals[from][msg.sender] = safeSub(approvals[from][msg.sender], value);
 balances[from] = safeSub(balances[from], value);
 balances[to] = safeAdd(balances[to], value);
 Transfer( from, to, value );
 return true;
}

function approve(address spender, uint value) returns (bool) {
 approvals[msg.sender][spender] = value;
 Approval( msg.sender, spender, value );
 return true;
}

function allowance(address owner, address spender) constant returns (uint) {
 return approvals[owner][spender];
}

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