0

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);

}
1

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

  • I get an error saying 'Cannot read property '0' of undefined when I do it this way – DCKTF May 23 '18 at 8:14
  • you are right, I updated the code. However, what version of web3 are you using?. what you did actually works in 0.14 but i think it doesn't work in 1.0. this should work in both. Let me know how it goes. – Jaime May 23 '18 at 9:27
  • I'm using 0.20.1 I think, loading it over cdn.jsdelivr.net/npm/web3@0.20.1/dist/web3.min.js. The code still doesn't seem to work.. I'm getting an undefined result – DCKTF May 23 '18 at 10:18
  • then the problem is not that the account is not correct. I have a website that does what you are doing and I am also using web3. Take a look at the update on the answer. let me know if it works for you. – Jaime May 23 '18 at 10:43
  • Still not working, but I actually found a way to integrate it into the form I was already building, and there it works! – DCKTF May 23 '18 at 12:13

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.