New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add abi.encodeError
similarly to abi.encodeCall
#14287
Comments
This issue has been marked as stale due to inactivity for the last 90 days. |
This issue has been marked as stale due to inactivity for the last 90 days. |
This issue has been marked as stale due to inactivity for the last 90 days. |
still relevant |
In either case, in the future we consider allowing to declare local variables of error type and being able to pass them along. As in:
or in the latter version something more like
(which works much less gracefully until we switch to postfix types and is also less ideal until we have polymorphic functions) In either case, the (only possible) semantics of these would be for the variable And thus, the saner way to access the abi-encoding of an error would be by mere explicit conversion, as in Now we can consider going the easier route of |
Abstract
Using
abi.encodeCall
for encoding errors fails with errorIt would be nice to have a
abi.encodeError
that works similarly toabi.encodeCall
, but for custom errors.Motivation
Both functions and error include a
.selector
getter that returns thebytes4
"signature". In the case of a function selector, this can be used, along withabi.encodeWithSelector
to generate the bytes corresponding to a function call. Similarly,abi.encodeWithSelector
can be used to encode a custom error.abi.encodeCall
is a safer alternative that verifies the type and number or arguments at compile type. Whileabi.encodeCall
works well with functions, it does not currently support errors.Being able to generate the bytes corresponding to custom errors can be particularly usefull for testing with Foundry.
Specification
Given a custom error
Enable the syntax
abi.encodeError(SomeErrorName, (arg0, arg1, arg2, arg3));
that returns the same as
with the same type checking as
abi.encodeCall
Backwards Compatibility
None. This is introducing a new syntax that doesn't conflict with existing ones.
The text was updated successfully, but these errors were encountered: