24

(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

eth
  • 85,679
  • 53
  • 285
  • 406
manidos
  • 4,298
  • 3
  • 31
  • 55

1 Answers1

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).

eth
  • 85,679
  • 53
  • 285
  • 406