In the Create-React box from Truffle, why do we retrieve a uint value from a function call with "result.c" instead of "result"? What's the c?
This strikes me as bad code. When a number is returned from a contract, it's of type
It can also be converted to a number via
.toNumber(), but be careful about loss of precision. The reason
BigNumber or string form (or perhaps hex).
In regard to result.c
result is a BigNumber object in this case — rather counterintuitively I suspect you thought you would get back a single uint (who wouldn’t!), but because uint256 is larger than JS can handle the value is wrapped in a BigNumber object, what you’ve accessed (via
result.c) is the coefficient which returns an array, the first index being the value, and the second index is the exponent.
Credit to rxdizzle for the explanation.