Solidity – Instance.balanceOf(…).call is Not a Function: Troubleshooting

soliditytestingtruffle

I have ERC20 standard token functions in my code…I´m trying to test the function balanceOf(address _owner) with a javascript test on truffle but I have the following problem:

 TypeError: ovxet.balanceOf(...).call is not a function
  at test/test1.js:48:46

It´s weird, because I always pay attention on how I define the functions in the code and how I have to call them…

I´ve tried in my test in both ways (async/await and promise chaning) but the result is the same "is not a function":

it("should call balance", function() {
    account1 = accounts[0];
    return OVXET.deployed().then(function(instance) {
        ovxet = instance;
        return ovxet.balanceOf(account1).call({from: account1});
    }).then(function(balance){
        console.log(balance);
    });
});

And this async/await call inside another promise:

    var balance2 = await ovxet.balanceOf(account1).call({from: account1});
    console.log("balance using erc20 function: " + balance2.toNumber());

Here you have the code inside the .sol script:

function balanceOf(address _owner) public constant returns (uint balance) {
    return _sumBalances(_owner);
}

It´s really strange because It´s so easy coding-function…so I am really frustrating with this situation…

This is the ABI part related to this function:

{
      "constant": true,
      "inputs": [
        {
          "name": "_owner",
          "type": "address"
        }
      ],
      "name": "balanceOf",
      "outputs": [
        {
          "name": "balance",
          "type": "uint256"
        }
      ],
      "payable": false,
      "stateMutability": "view",
      "type": "function"
    },

Best Answer

In Truffle v4.xx you should be able to call a functions like this

return OVXET.deployed().then(function(instance) {
    ovxet = instance;
    return ovxet.balanceOf.call(account1, {from: account1});
}).then(function(balance){
    console.log(balance);
});

The syntax is contract.method.call(param1, param2, ..).