admin管理员组文章数量:1406944
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.
本文标签: smartcontractsHow to interpret javascript BN objectStack Overflow
版权声明:本文标题:smartcontracts - How to interpret javascript BN object? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744685446a2619670.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论