11

I am quite new to this. Please help me out. I am trying to build a dapp using meteor. I am having a little trouble with calling a function of the contract using web3. Here's the code snippet that's trying to call the function of the contract:

myContract.startAFunc.sendTransaction(
  "Name",{from: fromaddress, value: 500000000000000000},
  function(err,address) {
    if(!err)
      console.log(address);});

//myContract is the ABI array at the contract address, startAFunc is the function name

The function prototype is as follows:

function startABet(string _Input} payable

I am getting this error:

Uncaught Error: new BigNumber() not a number: [object Object]

The code was working a while ago. I wanted to make a little modification by sending a variable instead of a hard coded value, but was not able to do so. Later I tried to revert back, now this is not working either. Can anyone please tell me what is the wrong that I am doing here. I have spent days on this, but haven't been able to figure it out. I am running it on chrome browser with metamask extension on a ubuntu machine.

  • My guess is your fromaddress is something wierd that web3 doesn't know how to handle. The error is somewhere in your javascript, not your solidity. Try logging out some more variables. – Aakil Fernandes Mar 7 '17 at 21:00
  • how do the variable fromaddress gets value ? i think the javascript is still loaded so sometime you need to enforce the refresh to use the updated version. – Badr Bellaj Mar 7 '17 at 22:36
  • well, had declared the fromaddress in the initial part of the code. So, it's just a variable that stores the address. – Anki Mar 9 '17 at 3:20
13

We get these occasionally when we make a change to MyEtherWallet, and we don't use Solidity or web3. It's a JS thing in the BigNumber.js library that web3 also uses.

Somewhere you have something that you think is a number but it's actually a string, null, array, object, or something else. This was some code for sending a signed TX via the offline tab. The error in our case was BigNumber Error: new BigNumber() not a number: 0x. And the fix:

  • [before] $scope.tx.value = etherUnits.toEther('0x'+eTx.value.toString('hex'),'wei');
  • [after] $scope.tx.value = eTx.value.toString('hex')!='' ? etherUnits.toEther('0x'+eTx.value.toString('hex'),'wei') : 0;

So before we were just like "take that value and do stuff with it". The fix was "if this value isn't empty, then do stuff with it, otherwise return 0.

So. Things to try...

  • console.log your variables before AND after, error or no error, and also log their types: console.log(typeof myContract)

  • Make sure that you are catching any empty or null values and either retuning a number (e.g. 0), or not continuing on

  • Make sure you are passing what you think you are passing. For example, are you really passing the address, or fromaddress, or contract.address, or something else?

  • In your case, it's saying [Object object], which makes me think something is an object. In that case do console.log( JSON.stringify(myContract) ) as well so you can actually see what it is.

  • Anything that you log that returns something funky like Object { s: 1, e: 0, c: Array1 }, you need to either

    • toString to get it's value as a decimal string
    • toNumber to approximate it as a JS number.
    • (That object is the object from BigNumber.js)

If you do all of those things, you will discover the spot where you thought something was something, but it was actually somethingElse. Then it's an easy fix.

  • Thank you for helping me solve this problem, you're a beautiful person :D – Merunas Grincalaitis Aug 28 '17 at 19:02
3

I also faced the similar issue, the possible reason could be, you are entering any parameter wrong. Please check if you are providing correct values of:

  • Contract ABI
  • Contract Address
  • from (address)
  • to (address)
  • amount

Take care of any typo. As in my case, I wrote form instead of from.

1

I made some changes to my contracts. I deleted my compiled files and recompiled them. That seemed to do the trick.

0

Well, I tried all the possibilities mentioned above, none worked. Was about to give up and was just messing around the code and changed the name of the function in my contract, did no other changes whatsoever. Out of the blue, it actually worked.! I still can't figure out what the problem was and what the relationship between bignumber and the name of the function was, but it actually worked.!

  • 1
    Maybe you did not initialize myContract correctly or you had a mismatch between ABI and bytecode? Then after changing the name and possibly re-deploy it worked? – Validity Labs - Sebastian Mar 9 '17 at 14:28
  • Well, I had tried redeploying the same contract and using that ABI and re-initializing it. But ya, what you said might be a possibility and I might've overseen the detail. Thanks.. – Anki Mar 13 '17 at 23:04
0

for me, i was getting the error because i was using

web3.eth.getBalance.request(address)

instead of

web3.eth.getBalance(address)

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.