I have a contract with the decimals hardcoded to 8

    // Hardcoded to be a constant
    uint8 public constant decimals = 8;

I think this is the reason Im having problems with wallets and explorer to show token balances..

Metamask says: "We had trouble loading your token balances. You can view them here"

How can I show correctly my tokens?

Also can be possible to use 18 decimals, but then I would need to modify this:

    // constant to simplify conversion of token amounts into integer form
    uint256 public tokenUnit = uint256(10)**decimals;

Any tip about what can be the best solution and how I can do it?


  • Where is the rest of your contract? Jun 14 '20 at 20:28
  • Trying 'uint8 public decimals;' and later in the constructor settings to 8 decimals still a problem...Now at least Metamask shows the token name and balance set to 0.
    – Ecofintech
    Jun 14 '20 at 20:30
  • I still testing and seems an issue regarding Solidity version...something I'm doing wrong because this is an original contract from 0.4.19 that I upgraded...
    – Ecofintech
    Jun 14 '20 at 21:14
  • solved. I will came back with the solution, because I modified several things and not sure which one solved it..
    – Ecofintech
    Jun 14 '20 at 23:18
  • The problem was that I changed some basics of the ERC20 standard...
    – Ecofintech
    Jun 14 '20 at 23:58

Your contract is not ERC20-compliant.

More specifically, it does not implement function balanceOf as dictated by the standard:

Returns the account balance of another account with address _owner.

function balanceOf(address _owner) public view returns (uint256 balance)

I noticed that you have implemented something similar in your contract:

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

So it looks like you just need to rename it from tokenBalanceOf to balanceOf.

I would also get rid of the balance variable name in the function declaration, because it adds confusion, and because it is possibly even harmful. I'm not really sure how the Solidity compiler handles the ambiguity in this function, i.e., whether it returns balance (which is obviously always set to 0) or balances[_owner].

  • Thanks! I touched too much. I will review that suggestion about the 'balance' variable.
    – Ecofintech
    Jun 15 '20 at 0:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.