indutny / bn.js

BigNum in pure javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Converting json.stringified BN back into BN

0xCactus opened this issue · comments

Applied JSON.stringify on BN which gave me "{"_bn":{"negative":0,"words":[22127744,7770787,46556922,61120705,33815569,32632618,19307227,5865125,41554856,1514719,0],"length":10,"red":null}}". Any idea how I may convert this back into an instance of BN?

You need serialize BN as String in JSON.stringify and create a new BN from String in JSON.parse.

You serialize BN as String in JSON.stringify and create a new BN from String in JSON.parse.

@fanatid JSON.parse converts it to an object of {"_bn":{"negative":0,"words":[22127744,7770787,46556922,61120705,33815569,32632618,19307227,5865125,41554856,1514719,0],"length":10,"red":null}} without the BN class method. I tried passing the object into new BN(object) but the BN created is off from the original BN