[Ethereum] Keep getting error ‘Invalid number of arguments to Solidity function web3.js

web3js

I keep getting the same error saying

Uncaught Error: Invalid number of arguments to Solidity function
    at Object.InvalidNumberOfSolidityArgs (inpage.js:1)
    at u.validateArgs (inpage.js:1)
    at u.toPayload (inpage.js:1)
    at u.call (inpage.js:1)
    at u.execute (inpage.js:1)
    at gitter.js:21

this is the javascript code, it seems like the contract is not being loaded correctly, because also when I console log myAccount it returns undefined..

This is the javascript

if (typeof web3 !== 'undefined') {
  web3 = new Web3(web3.currentProvider);
} else {
  web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/<token>"));
}

web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/<token>"));
// web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

var tokenContract = web3.eth.contract(human_standard_token_abi);
var tokenRunning = tokenContract.at('0x5780a5928becc986edd597991a1a1af6357fdf05');

var myAccount = web3.eth.accounts[0];

if(!web3.isConnected()) {

  alert ('not connected');

} else {

  console.log('Balance of ' + myAccount + ' is equal to ' + tokenRunning.balanceOf(myAccount).toNumber() + ' tokens');
  // console.log(myAccount);

}

Best Answer

In your code there seem to be an issue with the account. You are using:

var myAccount = web3.eth.accounts[0];

Instead, you should do:

var accounts 
web3.eth.getAccounts(function(err,result){
    if(!err){
        accounts = result;
    }
});

var myAccount = accounts[0];

Hope this helps

UPDATE:

Getting the value from the contract:

var tokenContract = web3.eth.contract(human_standard_token_abi);
var tokenRunning = tokenContract.at('0x5780a5928becc986edd597991a1a1af6357fdf05');
tokenRunning.balanceOf(myAccount,function(err,result){
    if(!err){
        console.log(result)
    }
})

If the result is a "BigNumber" you can transform to string using result.toString(10)

Hope this helps