We have received an interesting feature request from @drortirosh (Easy type-safe encoding a method call. · Issue #11849 · ethereum/solidity · GitHub) and we’d like get more feedback on how useful it would be to you in practice.
The feature would provide a way to ABI-encode a function call with
abi.encodeWithSelector() by calling a helper method on that function.
So for example
C.foo.encode(x, y, z) would return a
bytes array containing an encoded representation of a function call with selector
C.foo.selector and values of
z encoded as parameters according to the function signature. Unlike
abi.encodeWithSelector(), it could ensure that the representation actually contains a function selector, and that it has the right number of arguments and the right argument types.