Skip to content

Conversation

@joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented Jul 31, 2025


PR-Codex overview

This PR focuses on improving the decodeFunction and decodeError functionalities in the thirdweb package by enhancing error handling and ensuring the correct ABI function or error is found based on the provided selector.

Detailed summary

  • Updated decodeFunctionData.ts to filter ABI functions and throw an error if none is found.
  • Updated decodeFunctionResult.ts similarly to handle ABI function filtering and error throwing.
  • Enhanced decodeError.ts to filter ABI errors and throw an error if none is found.
  • Added a test case in decodeFunctionData.test.ts to validate correct decoding of function data.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of function and error data decoding, with enhanced error handling for unmatched selectors.
  • Tests

    • Added a new test to verify correct decoding of function data.

@vercel
Copy link

vercel bot commented Jul 31, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 31, 2025 8:56am
nebula ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 31, 2025 8:56am
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 31, 2025 8:56am
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 31, 2025 8:56am
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 31, 2025 8:56am

@changeset-bot
Copy link

changeset-bot bot commented Jul 31, 2025

🦋 Changeset detected

Latest commit: 2dad5b6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
thirdweb Patch
@thirdweb-dev/nebula Patch
@thirdweb-dev/wagmi-adapter Patch

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 31, 2025

Walkthrough

This change updates the decoding logic for ABI functions and errors in the "thirdweb" package by replacing the use of ox__AbiFunction.fromAbi and ox__AbiError.fromAbi with explicit filtering of ABI entries based on selector matching. It also adds a new test for function data decoding and includes a patch note.

Changes

Cohort / File(s) Change Summary
Patch Note
.changeset/tangy-ghosts-joke.md
Added a changeset describing a patch to fix decodeFunction and decodeError functions in the "thirdweb" package.
ABI Error Decoding Logic
packages/thirdweb/src/utils/abi/decodeError.ts
Replaced the usage of ox__AbiError.fromAbi with manual filtering of ABI entries for errors matching the selector; throws error if not found.
ABI Function Data Decoding Logic
packages/thirdweb/src/utils/abi/decodeFunctionData.ts, packages/thirdweb/src/utils/abi/decodeFunctionResult.ts
Updated both files to replace ox__AbiFunction.fromAbi with explicit filtering of ABI for functions matching the selector; added explicit error handling for missing selectors.
Function Data Decoding Test
packages/thirdweb/src/utils/abi/decodeFunctionData.test.ts
Added a new test verifying correct decoding of function data using a contract instance and snapshot assertion.

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
Loading
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
Loading

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

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch Fix_decodeFunction_and_decodeError_functions

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Jul 31, 2025
@joaquim-verges joaquim-verges changed the title Fix decodeFunction and decodeError functions [SDK] Fix decodeFunction and decodeError functions Jul 31, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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_CHAIN for 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

📥 Commits

Reviewing files that changed from the base of the PR and between ed65f4c and 2dad5b6.

📒 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 @/types or local types.ts barrels
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless 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.ts
  • packages/thirdweb/src/utils/abi/decodeFunctionData.test.ts
  • packages/thirdweb/src/utils/abi/decodeError.ts
  • packages/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.ts
  • packages/thirdweb/src/utils/abi/decodeFunctionData.test.ts
  • packages/thirdweb/src/utils/abi/decodeError.ts
  • packages/thirdweb/src/utils/abi/decodeFunctionData.ts
**/*.test.{ts,tsx}

📄 CodeRabbit Inference Engine (CLAUDE.md)

**/*.test.{ts,tsx}: Place tests alongside code: foo.tsfoo.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
Use FORKED_ETHEREUM_CHAIN for mainnet interactions and ANVIL_CHAIN for 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.

Comment on lines +36 to +42
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)}`);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

@github-actions
Copy link
Contributor

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 63.15 KB (+0.02% 🔺) 1.3 s (+0.02% 🔺) 334 ms (+168.33% 🔺) 1.6 s
thirdweb (cjs) 353.02 KB (0%) 7.1 s (0%) 1.1 s (+11.92% 🔺) 8.1 s
thirdweb (minimal + tree-shaking) 5.7 KB (0%) 114 ms (0%) 92 ms (+1235.88% 🔺) 206 ms
thirdweb/chains (tree-shaking) 526 B (0%) 11 ms (0%) 32 ms (+790.51% 🔺) 43 ms
thirdweb/react (minimal + tree-shaking) 19.3 KB (0%) 386 ms (0%) 77 ms (+387.75% 🔺) 463 ms

@codecov
Copy link

codecov bot commented Jul 31, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.42%. Comparing base (ed65f4c) to head (2dad5b6).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...kages/thirdweb/src/utils/abi/decodeFunctionData.ts 66.66% 3 Missing ⚠️

❌ 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              
Flag Coverage Δ
packages 56.42% <66.66%> (-0.01%) ⬇️
Files with missing lines Coverage Δ
...kages/thirdweb/src/utils/abi/decodeFunctionData.ts 68.00% <66.66%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joaquim-verges joaquim-verges merged commit e4ba47b into main Jul 31, 2025
26 of 27 checks passed
@joaquim-verges joaquim-verges deleted the Fix_decodeFunction_and_decodeError_functions branch July 31, 2025 22:33
@joaquim-verges joaquim-verges mentioned this pull request Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages SDK Involves changes to the thirdweb SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants