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.
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.
Share Improve this question edited Jun 12, 2021 at 7:06 jarvis1234d asked Jun 12, 2021 at 6:16 jarvis1234djarvis1234d 811 silver badge5 bronze badges 4- 2 what is this BN object? That's not a javascript built in - does this documentation help – Jaromanda X Commented Jun 12, 2021 at 6:18
- 2 If you are receiving a BN object already, probably you just need to use needed methods to get the number value: bn.toString(base, length), bn.toNumber(), etc – Eddy Commented Jun 12, 2021 at 7:41
- I would guess it is this library. – President James K. Polk Commented Jun 12, 2021 at 14:18
- 1 The number represented appears to 10000000000000000000000. But this is based on analyzing the current internals of the source code. This can change over time, thus you should always use the methods suggested by @Eddy – President James K. Polk Commented Jun 12, 2021 at 14:29
2 Answers
Reset to default 4I am a bit late, but you can convert your function oute like the following:
oute = await app.balanceOf(0x....)
oute.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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744685446a4587887.html
评论列表(0条)