0

I just deployed the token smart contract and Etherscan shows the TotalSupply with all 18 decimals for some reason. Basically, it shows excessive 18 zeroes in the TotalSupply section. Could you please explain what's wrong with the code, which is very simple? Please see attached and thank you in advance!

pragma solidity ^0.8.17;
///SPDX-License-Identifier: MIT
    
abstract contract EIP20Interface {
    // total amount of tokens
    uint256 public totalSupply;

    // @param _owner The address from which the balance will be retrieved
    // @return The balance
    function balanceOf(address _owner) virtual public view returns (uint256 balance);

    // @notice send `_value` token to `_to` from `msg.sender`
    // @param _to The address of the recipient
    // @param _value The amount of token to be transferred
    // @return Whether the transfer was successful or not
    function transfer(address _to, uint256 _value) virtual public returns (bool success);

    // @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
    // @param _from The address of the sender
    // @param _to The address of the recipient
    // @param _value The amount of token to be transferred
    // @return Whether the transfer was successful or not
    function transferFrom(address _from, address _to, uint256 _value) virtual public returns (bool success);

    // @notice `msg.sender` approves `_spender` to spend `_value` tokens
    // @param _spender The address of the account able to transfer the tokens
    // @param _value The amount of tokens to be approved for transfer
    // @return Whether the approval was successful or not
    function approve(address _spender, uint256 _value) virtual public returns (bool success);

    // @param _owner The address of the account owning tokens
    // @param _spender The address of the account able to transfer the tokens
    // @return Amount of remaining tokens allowed to spent
    function allowance(address _owner, address _spender) virtual public view returns (uint256 remaining);
  
      // solhint-disable-next-line no-simple-event-func-name
    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 "./EIP20Interface.sol";

contract XXXXX is EIP20Interface {

    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];
    }
}
4
  • What were your constructor args? Apparently, you're supposed to pass the number of decimals there, did you?
    – Foxxxey
    Commented Nov 23, 2022 at 1:53
  • I entered the total token supply amount with decimals in the "_initialAmount" section of Remix when deploying the contract. However, when the contract is deployed, Etherscan shows TotalSupply with extra 18 zeroes (decimals) in Contract/Read Contract section. Max Total Supply in Etherscan show the correct amount and the correct amount has been received by the contract deployer, so the issue is only with the TotalSupply amount in Etherscan Read Contract section. @Foxxxey Commented Nov 23, 2022 at 18:39
  • Oh, the TotalSupply() function you mean? It works as intended, it s supposed to return the raw number, not to convert it in ether.
    – Foxxxey
    Commented Nov 24, 2022 at 18:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.