0

I have a function which returns an uint, but actually gets an object - how is that converted.

e.g.

f

   "0x91f35a1267f2c8d763f7a3fb35ffac845fcbb1417a64b030ed79cbaa4e29694f"

f is defined as the return to the following function:

function testReturn() returns (uint) {
    studentAge=90;
    return 89;
 }

There must be a way to convert the return from this function.

The contract is defined as:

contract CollegeAdmin {
    uint8 public studentAge=21;
    uint16 public studentIncome=15000;
    uint8 public studentScore=4;

    uint8 public studentAttendance=96;

    function testReturn() returns (uint) {
        studentAge=90;
        return 89;
    }
}

Hence f is defined using:

f = con.testReturn()

Also, con is defined:

con = eth.contract(abi).at(addr)

abi - abi for contract addr - contract address

Trevor Lee Oakley
  • 2,327
  • 2
  • 19
  • 48

2 Answers2

1

I tested by adding constant and that worked. I am unsure what it returned before, but with constant added it worked -

   function testReturn() constant returns (uint) {
       studentAge=90;
       return 89;
   }
Trevor Lee Oakley
  • 2,327
  • 2
  • 19
  • 48
0

Non-contract functions can not return values. Use Events instead.

Or mark your function constant (or view) (if the function doesn't modify the state).

function testReturn() constant returns (uint) {
    studentAge=90;
    return 89;
 }

The following statements are considered modifying the state:

  • Writing to state variables.
  • Emitting events.
  • Creating other contracts.
  • Using selfdestruct.
  • Sending Ether via calls.
  • Calling any function not marked view or pure.
  • Using low-level calls.
  • Using inline assembly that contains certain opcodes.

If you are not reading any state variables better make function pure.

function testReturn() pure returns (uint) {
        return 89;
     }

Read more about view functions and pure functions.

Prashant Prabhakar Singh
  • 8,026
  • 5
  • 40
  • 79