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.


1 Answer 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.

Your Answer

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

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