[Ethereum] How to parse and deal with BigNumber (BN) args in Solidity events

bignumbereventssolidityweb3js

In the past, web3 events published numeric events like so:

BigNumber { s: 1, e: 17, c: [ 1000 ] } }

Now with web3.js 1.0, big numbers come down as objects like this:

 <BN: de0b6b3a7640000>

The problem here is that if we're collecting events for troubleshooting later, this would be indecipherable. The only solution I can think of is having some code in the event consumer convert the number before storing the event somewhere like so:

web3.utils.fromWei(new web3.utils.BN(receipt.logs[0].args.amount))

Does anyone else have any other ideas?

Best Answer

You have access to yourBigNumber.toString(10), .toString(16) and .toNumber(), no?

Look at this cheatsheet https://github.com/MikeMcl/bignumber.js

Related Topic