Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goal
Solidity allows overloading functions & events - that is to say, you can for example have multiple events with the same name. To avoid this being an issue, Solidity converts ABI entries to a signature which is then used to generate a "selector" (a part of the hash of the signature)
Generating this signature with a static type is important for downstream libraries like
viem
because the current lack of this feature means viem can't differentiate between events/functions with the same name leading to subtle bugs and bypassing this limitation requires dropping type safety in viem.Open questions
parse
). This is because signatures are lossy so you can't really compute the inverse anyway (but maybe somebody would benefit from even a partial inverse)human-readable
folder since it felt like the closest place to add it, but this code doesn't fit particularly well in any of the existing folders I feel. Open to thoughts on thisTest
Test
Type test
PR-Codex overview
This PR focuses on enhancing the
abitype
package by introducing thesignatureAbiItem
function for generating ABI signatures, improving type safety, and adding related tests and benchmarks.Detailed summary
signatureAbiItem
function to format ABI items into signatures.UnknownTypeError
,InvalidAbiItemError
, andsignatureAbiItem
.tupleRegex
to be exported.signatureAbiItem
.signatureAbiItem
functionality.abitype
withethers
library.