-
Notifications
You must be signed in to change notification settings - Fork 619
[SDK] Fix decodeFunction and decodeError functions #7767
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
[SDK] Fix decodeFunction and decodeError functions #7767
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
🦋 Changeset detectedLatest commit: 2dad5b6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughThis change updates the decoding logic for ABI functions and errors in the "thirdweb" package by replacing the use of Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant decodeFunctionData
participant ABI
Caller->>decodeFunctionData: Provide ABI and encoded data
decodeFunctionData->>ABI: Filter for function with matching selector
alt Function found
decodeFunctionData->>decodeFunctionData: Decode data with ABI function
decodeFunctionData-->>Caller: Return decoded result
else Function not found
decodeFunctionData-->>Caller: Throw error (missing selector)
end
sequenceDiagram
participant Caller
participant decodeError
participant ABI
Caller->>decodeError: Provide ABI and error data
decodeError->>ABI: Filter for error with matching selector
alt Error found
decodeError->>decodeError: Decode error with ABI error
decodeError-->>Caller: Return decoded error
else Error not found
decodeError-->>Caller: Throw error (missing selector)
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/thirdweb/src/utils/abi/decodeFunctionData.test.ts (1)
7-25: Consider using ANVIL_CHAIN for isolated testing.The test follows good practices with real function invocations and deterministic data. However, per the coding guidelines, consider using
ANVIL_CHAINfor isolated tests if this doesn't require specific mainnet interactions.If network isolation is preferred:
- chain: defineChain(17177), + chain: ANVIL_CHAIN,
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
.changeset/tangy-ghosts-joke.md(1 hunks)packages/thirdweb/src/utils/abi/decodeError.ts(2 hunks)packages/thirdweb/src/utils/abi/decodeFunctionData.test.ts(1 hunks)packages/thirdweb/src/utils/abi/decodeFunctionData.ts(1 hunks)packages/thirdweb/src/utils/abi/decodeFunctionResult.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (CLAUDE.md)
**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each file to one stateless, single-responsibility function for clarity
Re-use shared types from@/typesor localtypes.tsbarrels
Prefer type aliases over interface except for nominal shapes
Avoidanyandunknownunless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial,Pick, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose
Files:
packages/thirdweb/src/utils/abi/decodeFunctionResult.tspackages/thirdweb/src/utils/abi/decodeFunctionData.test.tspackages/thirdweb/src/utils/abi/decodeError.tspackages/thirdweb/src/utils/abi/decodeFunctionData.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit Inference Engine (CLAUDE.md)
Load heavy dependencies inside async paths to keep initial bundle lean (lazy loading)
Files:
packages/thirdweb/src/utils/abi/decodeFunctionResult.tspackages/thirdweb/src/utils/abi/decodeFunctionData.test.tspackages/thirdweb/src/utils/abi/decodeError.tspackages/thirdweb/src/utils/abi/decodeFunctionData.ts
**/*.test.{ts,tsx}
📄 CodeRabbit Inference Engine (CLAUDE.md)
**/*.test.{ts,tsx}: Place tests alongside code:foo.ts↔foo.test.ts
Use real function invocations with stub data in tests; avoid brittle mocks
Use Mock Service Worker (MSW) for fetch/HTTP call interception in tests
Keep tests deterministic and side-effect free
UseFORKED_ETHEREUM_CHAINfor mainnet interactions andANVIL_CHAINfor isolated tests
Files:
packages/thirdweb/src/utils/abi/decodeFunctionData.test.ts
🧠 Learnings (6)
📓 Common learnings
Learnt from: AmineAfia
PR: thirdweb-dev/js#7415
File: apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/webhooks/utils/abiUtils.ts:31-42
Timestamp: 2025-06-23T13:33:05.770Z
Learning: In the thirdweb webhooks ABI utilities, validation of ABI inputs is performed upstream using the `isAbiInput` function before calling `getCanonicalType`. The `getCanonicalType` function only receives pre-validated inputs, so additional runtime validation within the function would be redundant.
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : EIP-1193, EIP-5792, EIP-7702 standard support in wallet modules
.changeset/tangy-ghosts-joke.md (3)
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Surface breaking changes prominently in PR descriptions
Learnt from: MananTank
PR: #7298
File: apps/dashboard/src/app/nebula-app/move-funds/move-funds.tsx:424-424
Timestamp: 2025-06-06T23:46:08.795Z
Learning: The thirdweb project has an ESLint rule that restricts direct usage of defineChain. When it's necessary to use defineChain directly, it's acceptable to disable the rule with // eslint-disable-next-line no-restricted-syntax.
Learnt from: MananTank
PR: #7332
File: apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/nft/overview/nft-drop-claim.tsx:82-90
Timestamp: 2025-06-13T13:03:41.732Z
Learning: The thirdweb contract object is serializable and can safely be used in contexts (e.g., React-Query keys) that require serializable values.
packages/thirdweb/src/utils/abi/decodeFunctionResult.ts (2)
Learnt from: AmineAfia
PR: #7415
File: apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/webhooks/utils/abiUtils.ts:31-42
Timestamp: 2025-06-23T13:33:05.770Z
Learning: In the thirdweb webhooks ABI utilities, validation of ABI inputs is performed upstream using the isAbiInput function before calling getCanonicalType. The getCanonicalType function only receives pre-validated inputs, so additional runtime validation within the function would be redundant.
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to src/extensions/** : Auto-generated contracts from ABI definitions in extensions
packages/thirdweb/src/utils/abi/decodeFunctionData.test.ts (5)
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to test/src/test-wallets.ts : Predefined test accounts are in test/src/test-wallets.ts
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to **/*.test.{ts,tsx} : Use real function invocations with stub data in tests; avoid brittle mocks
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to **/*.test.{ts,tsx} : Keep tests deterministic and side-effect free
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to **/*.test.{ts,tsx} : Use FORKED_ETHEREUM_CHAIN for mainnet interactions and ANVIL_CHAIN for isolated tests
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to src/extensions/** : Auto-generated contracts from ABI definitions in extensions
packages/thirdweb/src/utils/abi/decodeError.ts (2)
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to src/extensions/** : Auto-generated contracts from ABI definitions in extensions
Learnt from: AmineAfia
PR: #7415
File: apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/webhooks/utils/abiUtils.ts:31-42
Timestamp: 2025-06-23T13:33:05.770Z
Learning: In the thirdweb webhooks ABI utilities, validation of ABI inputs is performed upstream using the isAbiInput function before calling getCanonicalType. The getCanonicalType function only receives pre-validated inputs, so additional runtime validation within the function would be redundant.
packages/thirdweb/src/utils/abi/decodeFunctionData.ts (1)
Learnt from: AmineAfia
PR: #7415
File: apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/webhooks/utils/abiUtils.ts:31-42
Timestamp: 2025-06-23T13:33:05.770Z
Learning: In the thirdweb webhooks ABI utilities, validation of ABI inputs is performed upstream using the isAbiInput function before calling getCanonicalType. The getCanonicalType function only receives pre-validated inputs, so additional runtime validation within the function would be redundant.
🧬 Code Graph Analysis (1)
packages/thirdweb/src/utils/abi/decodeError.ts (1)
packages/thirdweb/src/exports/utils.ts (1)
AbiError(113-113)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: Size
- GitHub Check: E2E Tests (pnpm, vite)
- GitHub Check: E2E Tests (pnpm, webpack)
- GitHub Check: E2E Tests (pnpm, esbuild)
- GitHub Check: Unit Tests
- GitHub Check: Lint Packages
- GitHub Check: Build Packages
- GitHub Check: Analyze (javascript)
🔇 Additional comments (3)
.changeset/tangy-ghosts-joke.md (1)
1-6: LGTM! Changeset properly documents the patch.The changeset correctly identifies this as a patch-level change and provides a clear, concise description of the fix.
packages/thirdweb/src/utils/abi/decodeFunctionResult.ts (1)
35-45: LGTM! Consistent implementation of selector-based filtering.The manual filtering approach correctly identifies ABI functions by selector and provides clear error handling when no match is found. The implementation is consistent with the pattern used in other decoding utilities.
packages/thirdweb/src/utils/abi/decodeFunctionData.ts (1)
35-43: LGTM! Consistent selector-based filtering implementation.The manual filtering approach correctly identifies ABI functions by selector and provides clear error handling. The implementation maintains consistency with the other decoding utilities in this PR.
| const err = abi.filter( | ||
| (i) => i.type === "error" && AbiError.getSelector(i) === data.slice(0, 10), | ||
| ); | ||
| const abiError = err[0] as ox__AbiError.AbiError; | ||
| if (!abiError) { | ||
| throw new Error(`No ABI function found for selector ${data.slice(0, 10)}`); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix error message to reference "ABI error" instead of "ABI function".
The error message on line 41 incorrectly refers to "ABI function" when it should reference "ABI error" since this is the decodeError function.
- throw new Error(`No ABI function found for selector ${data.slice(0, 10)}`);
+ throw new Error(`No ABI error found for selector ${data.slice(0, 10)}`);🤖 Prompt for AI Agents
In packages/thirdweb/src/utils/abi/decodeError.ts around lines 36 to 42, the
error message incorrectly refers to "ABI function" instead of "ABI error".
Update the error message string on line 41 to say "No ABI error found for
selector" followed by the selector value to accurately reflect the context of
the decodeError function.
size-limit report 📦
|
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (66.66%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #7767 +/- ##
==========================================
- Coverage 56.42% 56.42% -0.01%
==========================================
Files 904 905 +1
Lines 58674 58699 +25
Branches 4139 4139
==========================================
+ Hits 33108 33119 +11
- Misses 25461 25475 +14
Partials 105 105
🚀 New features to boost your workflow:
|

PR-Codex overview
This PR focuses on improving the
decodeFunctionanddecodeErrorfunctionalities in thethirdwebpackage by enhancing error handling and ensuring the correct ABI function or error is found based on the provided selector.Detailed summary
decodeFunctionData.tsto filter ABI functions and throw an error if none is found.decodeFunctionResult.tssimilarly to handle ABI function filtering and error throwing.decodeError.tsto filter ABI errors and throw an error if none is found.decodeFunctionData.test.tsto validate correct decoding of function data.Summary by CodeRabbit
Bug Fixes
Tests