0

My question is nearly identical to: how to parse the value returned by truffle ?

Except that when I run:

bigNumberValue.toString()

i get

'[object Promise]'

but then if I treat as a promise and run:

bigNumberValue.toString().then(a=>{console.log(a)})

I get

balance1.toString(...).then is not a function

I am running Truffle v4.1.12 (core: 4.1.12). I am trying to get the value out of the BigNumber. Can anyone help?

  • I am running my code from a truffle test script. IE with the command "truffle test /path/to/my/file.js" --network ganache" – Test1 Test2 Jul 17 '18 at 16:00
1

bigNumberValue is a Promise as you state also in your question. However, the way you're handling the Promise is wrong.

This should work:

balance1.then(a => {
    console.log(a.toString())
})
  • Sorry I should have made it clear that I am working in a truffle test script. Your solution works perfectly in the truffle console. But when I do the same thing in a truffle test script, I get "balance0.then is not a function". I also tried balance0.get() but I get the error "balance0.get is not a function" – Test1 Test2 Jul 17 '18 at 15:58
  • It seems that balance1.toString() works from the truffle test script. Here is what confuses me: if I console.log(balance1) either from the truffle console or truffle test script I get "{ s: 1, e: 0, c: [ 0 ] }". But balance.toString() works from the test script, but does not work from the console... I don't understand the difference – Test1 Test2 Jul 17 '18 at 16:14

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.