5

I am getting a BigNumber() error from the standard token function balanceOf(). The function returns uint256, but it seems like it's returning an array of objects. Here is my javascript testing in Truffle:

      return tokFactory.createTok(100000,"tok",1,"tok",{from: accounts[0]}).then(function(txHash) { 
      tokFactory.getTokenAddress.call().then(function(tokenAddress) { 
      tok = Tok.at(tokenAddress);
      }).then(function() { 
    tok.balanceOf.call(tokFactory).then(function(balance) {
  assert.equal(balance.toNumber(), 100000, "100000 wasn't in the first   account");
});
  });
      });

Solidity function:

function balanceOf(address _owner) constant returns (uint256 balance) {
    return balances[_owner];
}
  • "The function returns uint256, but it seems like it's returning an array of objects". What makes you think this? Also, try replacing tok.balanceOf.call(tokFactory.address) – Tjaden Hess Jan 5 '17 at 22:56
  • Ok passing in the tokFactory address fixed it, thanks. – ethereal Jan 8 '17 at 17:55
  • Facing the same error. i am trying this return KNTInstance.balanceOf.call(accounts[0], {from: accounts[0]}); – Inzmam ul Hassan Dec 7 '17 at 13:03
2

the mistake is in

 tok.balanceOf.call(tokFactory).then(function(balance) 

you should call

tok.balanceOf.call(tokFactory.address)

get it? you should pass the uint256 address of the contract not it's object rappresentation

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.