1

I'm working on a proxy contract that will perform calls as follows:

bool success;
bytes memory returndata;
(success, returndata) = _to.call.value(_value)(_data);
require(success);

this works great, except that, if the call reverts with an error message, this function will simply reverts, hiding the reason string.

How can I retrieve the reason string (I assume in the returndata) and use if to revert properly

3

It is simpler than you think:

require(success, string (returndata));

See documentation for details. You may also forward raw bytes, but you will need to use assembly.

  • I tryed require(success, returndata); and started looking into assembly when it failled to compile ... thanks for proving how stupid I am :P – Amxx Apr 1 at 14:52

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.