0

I have this function from a Solidity contract.

SomeStruct public rr;

function getRatingResult() public constant returns(bytes32) {
    // rr is an instance of a struct variable that has a field winningContestantId
    return rr.winningContestantId;
}

And, I have this function from another contract.

DifferentStruct public lm;

function getAverageNumber() constant returns(uint256) {
    return lm.averageNumber;
}

In both cases the output is correct. However, in the first case I get output as a hex string. Whereas, in second case, I get output that looks similar to a JSON object. How does this variation happen? In general, for cases where there is only value to be returned, how can I get Solidity and web3 to output that value as a name-value pair in a JSON document? Can I?

  • Integer types are converted into a bignumber.js object. Javascript's integers cannot store integers used in solidity. It support .toString() to return the decimal representation as a string. – Ismael Nov 8 '17 at 6:13
  • Ok. What is the mapping between Solidity return types and web3js data types? – cogitoergosum Nov 8 '17 at 6:15
  • Sorry, but I'm not aware of official documentation about that, I'd search in the source of web3. – Ismael Nov 8 '17 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.