5

I'd like to get the return value of a low level call.

(bool success, ) = address(0x1234...7890).call{value:0}(callData);

This post discusses a solution that sounds like it should work, but it doesn't have a checkmark and I was unable to get the source working because that last copy command in the toBytes function does not exist. I tried experimenting in solidity assembly with mload and mstore to make that copy command, but I could not.

copy(_addr, btsptr, _len);

Does anyone have a complete solution that actually works for this? Or can anyone help me finish that posted pseudo code from the above-linked post?

LampShade
  • 640
  • 8
  • 22
  • 1
    Why not (bool success, bytes memory data) = ..., then you can return data? – goodvibration Jun 16 '20 at 04:59
  • Is that supposed to work? I haven’t seen that documented anywhere. I will try it today. – LampShade Jun 16 '20 at 11:08
  • It works only from solc 0.5.x onward, where call returns two values - success status and the data returned from the function. And the fact that you have (bool success, ) in your code implies that your on solc 0.5.x or higher. – goodvibration Jun 16 '20 at 11:13
  • That's exactly what I was looking for. Thanks! That seems so obvious, I'm not sure how I missed that. – LampShade Jun 16 '20 at 13:27

1 Answers1

4

Starting from solc 0.5, call returns two values:

  1. bool success, which indicates whether or not the function completed successfully
  2. bytes memory data, which is the actual data returned from the function

The comma in (bool success, ) = ... implies that you are already using solc 0.5 or higher.

So simply change it to (bool success, bytes memory data) = ..., and use data as desired.

goodvibration
  • 26,003
  • 5
  • 46
  • 86