Truffle Test – Accessing Value of Promise Object in Solidity

bignumbercontract-debuggingcontract-developmentsoliditytruffle-test

a.getB.call().then(function (f) { console.log(f[1][0]) });

outputs:

BigNumber { s: 1, e: 20, c: [ 5000000 ] }

How can I access the value in c?

How can I save object f to a javascript variable?

Since I am saving an array of arrays, can I get the length of the Promise object?

Best Answer

How can I access the value in c?

the number is not only what is contained inside c but the whole BigNumber notation, which is accessible with a f.toString()

How can I save object f to a javascript variable?

f.toString() will give you a string, which can be saved into a variable. Same as you can keep it inside the BigNumber object and use the .toString to access to a readable value

Since I am saving an array of arrays, can I get the length of the Promise object?

this question doesn't make sense given the answers above, that kind of structure is the internal representation of the number stored into the BigNumber object

Related Topic