...by Daniel Szego
quote
"On a long enough timeline we will all become Satoshi Nakamoto.."
Daniel Szego

Monday, December 18, 2017

Solidity and Truffle Tips and Tricks - BigNumber in javascript


Using the web3 javascript library from the user interface or from the a Truffle javascript unit testing, you can sometimes get an object that look somehow like: 

{[String: '5'] s: 1, e: 0, c: [5]}

It means the result has the BigNumber type, web3.js converts every integer that comes from solidity into BigNumber because solidity integers have a bigger range than javascript integers. Use simple the toNumber() call to convert, like:

result.toNumber();