Etherscan

幫助獎勵 0.05 美元 ETH:“totalSupply”在 Etherscan 上的讀取合約部分顯示額外的 18 個零(已更新)

  • November 24, 2022

我仍然不知道如何解決這個問題。已經用不同的更改部署了幾次契約,但問題尚未解決:(

基本上,這是一個具有 1,000,000 個代幣和 18 位小數的固定供應代幣合約。當合約通過 Remix 部署到主網時(_initialAmount 正確指示所有 18 個小數/零,即 1000000000000000000000000),Etherscan 顯示“totalSupply”在合約/讀取合約部分也有額外的 18 個零(這是錯誤的!)。Etherscan 中的最大總供應量顯示了正確的數量(1,000,000 個代幣),並且轉移到合約部署者的數量也是正確的(1,000,000),因此問題僅與 Etherscan 讀取合約部分中的“totalSupply”數量有關。請幫忙 - 可能需要更改契約參數,但它們對我來說很好……契約本身非常簡單,請參見下文。

將很樂意向首先提供幫助的任何人發送 0.05 ETH。

pragma solidity ^0.8.17;
   ///SPDX-License-Identifier: MIT
   
   interface XXXXXX {
   function balanceOf(address _owner) external view returns (uint256 balance);
   function transfer(address _to, uint256 _value) external returns (bool success);
   function transferFrom(address _from, address _to, uint256 _value) external returns (bool success);
   function approve(address _spender, uint256 _value) external returns (bool success);
   function allowance(address _owner, address _spender) external view returns (uint256 remaining);

   event Transfer(address indexed _from, address indexed _to, uint256 _value);
   event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
pragma solidity ^0.8.17;
   ///SPDX-License-Identifier: MIT

import "XXXXXX.sol";
contract ZZZZZZ is XXXXXX {

   uint256 public totalSupply;
   uint256 constant private MAX_UINT256 = 2**256 - 1;
   mapping (address => uint256) public balances;
   mapping (address => mapping (address => uint256)) public allowed;

   string public name;                   
   uint8 public decimals;                
   string public symbol;                 

   constructor (
       uint256 _initialAmount,
       string memory _tokenName,
       uint8 _decimalUnits,
       string memory _tokenSymbol
   ) public {
       balances[msg.sender] = _initialAmount;               
       totalSupply = _initialAmount;                        
       name = _tokenName;                                   
       decimals = _decimalUnits;                            
       symbol = _tokenSymbol;                               
   }

   function transfer(address _to, uint256 _value) override public returns (bool success) {
       require(balances[msg.sender] >= _value);
       balances[msg.sender] -= _value;
       balances[_to] += _value;
       emit Transfer(msg.sender, _to, _value); //solhint-disable-line indent, no-unused-vars
       return true;
   }

   function transferFrom(address _from, address _to, uint256 _value) override public returns (bool success) {
       uint256 allowance = allowed[_from][msg.sender];
       require(balances[_from] >= _value && allowance >= _value);
       balances[_to] += _value;
       balances[_from] -= _value;
       if (allowance < MAX_UINT256) {
           allowed[_from][msg.sender] -= _value;
       }
       emit Transfer(_from, _to, _value); //solhint-disable-line indent, no-unused-vars
       return true;
   }

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

   function approve(address _spender, uint256 _value) override public returns (bool success) {
       allowed[msg.sender][_spender] = _value;
       emit Approval(msg.sender, _spender, _value); //solhint-disable-line indent, no-unused-vars
       return true;
   }

   function allowance(address _owner, address _spender) override public view returns (uint256 remaining) {
       return allowed[_owner][_spender];
   }
}

這不是錯誤或錯誤。總供應量是代幣數量 * 小數位數。

Etherscan 只是在其前端將它們分開以獲得更好的視圖。

查看其他硬幣

在此處輸入圖像描述 在此處輸入圖像描述

我認為這是因為你寫了uint256 _initialAmountand totalSupply = _initialAmount;。因此,您在 on 上看到的結果_initialAmount與 on 相同totalSupply

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