[Ethereum] Issue with Ganche and Truffle with Metamask. Can’t load token balance

contract-invocationerc-223ganachemetamasktruffle

I'm testing to create a token in Truffle; it compiles fine, but it won't load the balance of the token in to Metamask. I've set the connection correct: it does load the ETH balances of the Ganache chain correctly.

I'm not sure as to what is going on. This is the contract:

pragma solidity ^0.5.0;

contract TestToken{
    // Track how many tokens are owned by each address.
    mapping (address => uint256) public balanceOf;

    string public name = "TestToken1";
    string public symbol = "TTO";
    uint8 public decimals = 18;

    uint256 public totalSupply = 1000000 * (uint256(10) ** decimals);

    event Transfer(address indexed from, address indexed to, uint256 value);

    constructor() public {

        balanceOf[msg.sender] = totalSupply;

    }


    function isContract(address _addr) private view returns (bool is_contract) {
        uint length;
        assembly {
            //retrieve the size of the code on target address, this needs assembly
            length := extcodesize(_addr)
        }
        return length > 0;
    }

    function transfer(address to, uint256 value) public returns (bool success) {
        bytes memory empty;
        return transfer(to, value, empty);
    }

    function transfer(address to, uint256 value, bytes memory data) public returns (bool) {
        require(balanceOf[msg.sender] >= value);

        balanceOf[msg.sender] -= value;
        balanceOf[to] += value;
        emit Transfer(msg.sender, to, value);

       // if (isContract(to)) {
       //     ITokenReceiver(to).tokenFallback(msg.sender, value, data);
       // }
        return true;
    }

    event Approval(address indexed owner, address indexed spender, uint256 value);

    mapping(address => mapping(address => uint256)) public allowance;

    function approve(address spender, uint256 value)
        public
        returns (bool success)
    {
        allowance[msg.sender][spender] = value;
        emit Approval(msg.sender, spender, value);
        return true;
    }

    function transferFrom(address from, address to, uint256 value)
        public
        returns (bool success)
    {
        require(value <= balanceOf[from]);
        require(value <= allowance[from][msg.sender]);

        balanceOf[from] -= value;
        balanceOf[to] += value;
        allowance[from][msg.sender] -= value;
        emit Transfer(from, to, value);
        return true;
    }
}

As you can see its as basic as it gets. But in the Metamask console I see this:

ui.js:1 failed to load balance for token at 0xaec97fa2a3bd75ac77a431e06e5fa0aeb7e3083e
(anonymous) @……..

token updating failed Error: [ethjs-query] while formatting outputs from RPC '{"value":{"code":-32603,"message":"Internal JSON-RPC error.","data":{"originalError":{}},"stack":"Error: \"message\" must be a nonempty string.\n at new……

What is causing that RPC error? Is it me that made a mistake or some type of issue between ganache and Metamask?

Best Answer

This might work: MetaMask settings -> Advanced -> Reset Account.

Related Topic