0

I'm writing a Dapp, which connect the ether web3 provided by metamask.

How should I handle the response from contract method? I mean some methods that doesn't need to send a transaction.

for example, In my contract there's a public uint field and a public address field.

the code to get the uint field

contractIns.uintField(function(err, result){
     if(err){
         //error
     } else {
         //the data is in result.c[0];
     }
});

however, the code to get the address field

contractIns.addressField(function(err, result) {
     if(err){
         //error
     } else {
         //the result is the data itself
     }
});

I mean, is there any documentation about the format of return value format?

1 Answer 1

0

Solidity has integer types (like uint) that are too big for the javascript numeric type, so to avoid losing important data web3 will wrap integer types in a bignumber.js.

If you are sure the number is within the javascript range you can use the function toNumber to converto to a javascript numeric type.

contractIns.uintField(function(err, result){
     if(err){
         //error
     } else {
         //Use toNumber to convert to numeric type
         var myField = result.toNumber();
         console.log(myField);
     }
});

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.