Skip to content

feat(v1): split polymorphic from/fromAbi on Abi* modules into shape-specific helpers#245

Closed
jxom wants to merge 1 commit into
v1from
1.0/abi
Closed

feat(v1): split polymorphic from/fromAbi on Abi* modules into shape-specific helpers#245
jxom wants to merge 1 commit into
v1from
1.0/abi

Conversation

@jxom
Copy link
Copy Markdown
Member

@jxom jxom commented May 13, 2026

Splits the polymorphic from and fromAbi(abi, name | selector) helpers on AbiItem, AbiFunction, AbiEvent, and AbiError into shape-specific functions: fromHumanReadable, fromJson, fromAbiName, and fromAbiSelector.

The original polymorphic helpers are retained as @internal dispatchers so the shorthand decode/encode overloads keep working. AbiConstructor keeps fromAbi(abi) since constructors have no name or selector.

Abi.from now defaults to { prepare: true }, precomputing the signature hash on every item and removing the per-call keccak256 cost from the hot encode/decode path. Pass { prepare: false } to opt out.

Single-value collapse in AbiFunction.decodeResult and AbiError.decode, and the undefined return from AbiConstructor.decode for empty inputs, are unchanged.

- AbiFunction.from('function approve(address,uint256)')
+ AbiFunction.fromHumanReadable('function approve(address,uint256)')

- AbiFunction.from({ type: 'function', name: 'approve', /* ... */ })
+ AbiFunction.fromJson({ type: 'function', name: 'approve', /* ... */ })

- AbiFunction.fromAbi(abi, 'approve')
+ AbiFunction.fromAbiName(abi, 'approve')

- AbiFunction.fromAbi(abi, '0x095ea7b3')
+ AbiFunction.fromAbiSelector(abi, '0x095ea7b3')

- Abi.from(abi)                       // no `hash` precomputed
+ Abi.from(abi)                       // `hash` precomputed by default
+ Abi.from(abi, { prepare: false })   // opt out of `hash` precomputation

@vercel
Copy link
Copy Markdown

vercel Bot commented May 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ox Error Error May 13, 2026 6:10am

Request Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 13, 2026

Open in StackBlitz

npm i https://pkg.pr.new/ox@245

commit: c2988b1

…hape-specific helpers

Adds `fromHumanReadable`, `fromJson`, `fromAbiName`, and `fromAbiSelector` to
`AbiItem`, `AbiFunction`, `AbiEvent`, and `AbiError` (constructors keep just
`fromAbi` since they have no name or selector). The original polymorphic
`from` and `fromAbi(abi, name | selector)` overloads are now `@internal`
dispatchers retained to back the shorthand decode/encode overloads.

`Abi.from` now defaults to `{ prepare: true }`, precomputing the signature
`hash` on every item; pass `{ prepare: false }` to opt out.

Amp-Thread-ID: https://ampcode.com/threads/T-019e1fbe-3a01-77f5-a169-12d4f2967861
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant