23

(JS)

 var contract = web3.eth.contract(abiDefinition).at(address);
     contract.test(value, gotResult);
     function gotResult(error, result) {
            if(!error) {
                console.log(error);
            }
            else {
                console.log(result);
            }                               
    }

(SOL)

 contract A {
     function test(uint8 x) constant returns(uint8) {
         return x + 10;
     }
  }

(BROWSER)

enter image description here

1 Answer 1

24

result is a BigNumber object that is stringified to something like { [String: '5'] s: 1, e: 0, c: [ 5 ] }. You can use BigNumber methods, like result.toNumber() to see it better.

When integers are involved, web3.js uses BigNumber because native Javascript numbers are not large enough.

It's out of scope here to go into the internals of a general external library like BigNumber.

The main thing that helps is to recognize that when you get an object that looks like it, is that it's probably a BigNumber and you can call methods on it, as well as perform other additional BigNumber operations (without needing to know its internals).

2
  • 3
    What does S, C, E stand for?
    – user22075
    May 14, 2018 at 23:15
  • 10
    @quantumpotato According to the BigNumber repo, S stands for sign, E for exponent and C for coefficient (or significand). May 17, 2018 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.