3

So, I have a contract deployed which has a simple function which returns a uint.

If I make the function constant it returns the correct value set as a BigNumber object, but if I remove the constant keyword then it doesn't return a BigNumber object.

Can anyone throw some light as to why this happens? As far as I know, the constant keyword is used so that you don't have to pay gas for retrieving the value.

My contract function code :

function getMyNymber() returns (uint256) {
    return myNumber;
}

The above method doesn't return a Big Number object.

function getMyNymber() constant returns (uint256) {
    return myNumber;
}

This returns a Big Number object, the only difference being the constant keyword.

eth
  • 85,679
  • 53
  • 285
  • 406
Adnan Mulla
  • 141
  • 5
  • 1
    Related: https://ethereum.stackexchange.com/questions/765/what-is-the-difference-between-a-transaction-and-a-call – eth Nov 07 '17 at 06:57
  • 1
    @eth Thanks for that link, helped me understand the underlying concept more clearly ! – Adnan Mulla Nov 07 '17 at 17:17

1 Answers1

1

So I figured this out, if the function is not a constant function and requires gas to be executed then it requires a transaction to be sent and returns the transaction hash. Thus, I was getting the transaction hash instead of the actual value before making the function constant.

Adnan Mulla
  • 141
  • 5