Add abi.encodeError
similarly to abi.encodeCall
#14287
Labels
feature
low effort
There is not much implementation work to be done. The task is very easy or tiny.
low impact
Changes are not very noticeable or potential benefits are limited.
should have
We like the idea but it’s not important enough to be a part of the roadmap.
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: