Solidity Revert Opcode – Forward Revert Message from Low-Level Solidity Call

proxy-contractsrevert-opcodesolidity

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

Best Answer

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.

Related Topic