How to interpret javascript BN object?

Viewed 2230

While I was working on smart contract using truffle, whenever request some number like account balance or address from the truffle console; I receive a BN object which looks like this:

BN {
  negative: 0,
  words: [ 37748736, 3305132, 2220446, <1 empty item> ],
  length: 3,
  red: null
}

This object is part of bn.js library. But I am not able to find any documentation on how to interpret this object.

How do I read this. I want to learn what each field in this object means and be able to manually convert it to a normal number.

2 Answers

I am a bit late, but you can convert your function outcome like the following:

outcome = await app.balanceOf(0x....)
outcome.toNumber()

or even better:

(await app.balanceOf(0x....)).toNumber()

bn.js has a readme with examples.

You can convert the BN object to JS native Number using the .toNumber() function.

Related