7

For example, I have a contract like this:

contract example {
    mapping (uint => string) map;

    function example () {
        map[123] = "123";
    }

    function return1 () returns (string) {
        return map[123];
    }

    function return2 () returns (string) {
        return map[1];
    } 
}

When I'll call return1, it obviously returns '123', but what happens on return2?

4

Using your code as-is, when calling the return1() and return2(), you will have to send a transaction and you will be returned the transaction hash. If you are calling your return1() from another contract, your return value will be "123". If calling return2() from another contract, your return value will be an empty string "". See the following screen:

enter image description here

If I add the keyword constant to the return1() and return2() declaration, return2() will return the empty string "". See the following screen:

enter image description here

4

You should get an empty string, as if you'd done

function return2 () returns (string) {
   string my_string;
   return my_string;
}
4

in return2 you will get an empty string, in hex (0X000....000).

Your Answer

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

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