Skip to content

Conversation

@d4mr
Copy link
Contributor

@d4mr d4mr commented Aug 7, 2025

PR-Codex overview

This PR updates the readContract function in the src/server/routes/contract/read/read.ts file to enhance the handling of returnData by converting it to a JSON string and then parsing it back, improving data consistency.

Detailed summary

  • Added stringify import from thirdweb/utils.
  • Modified the result assignment in the response to use JSON.parse(stringify(returnData)) instead of returnData as any.

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of contract read results to ensure more consistent and reliable response formatting.

@d4mr d4mr requested a review from joaquim-verges August 7, 2025 20:59
@coderabbitai
Copy link

coderabbitai bot commented Aug 7, 2025

Walkthrough

The change updates the response handling in the readContract route by serializing the returnData using a stringify utility and then immediately parsing it back with JSON.parse before sending it in the response. An import for the stringify function from "thirdweb/utils" was also added.

Changes

Cohort / File(s) Change Summary
Read Contract Route Serialization
src/server/routes/contract/read/read.ts
Added import for stringify from "thirdweb/utils". Modified response logic to serialize and then parse returnData before inclusion in the response.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pb/contract-read-bigint-serialisation

🪧 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.
  • 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.

Copy link

@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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 067d5da and 0c0350d.

📒 Files selected for processing (1)
  • src/server/routes/contract/read/read.ts (2 hunks)
⏰ 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). (2)
  • GitHub Check: build
  • GitHub Check: lint
🔇 Additional comments (1)
src/server/routes/contract/read/read.ts (1)

6-6: LGTM!

The import addition is necessary for the stringify utility used later in the code.

reply.status(StatusCodes.OK).send({
// biome-ignore lint/suspicious/noExplicitAny: data from chain
result: returnData as any,
result: JSON.parse(stringify(returnData)) as any,
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify the necessity of the serialize-deserialize pattern.

The code now performs JSON.parse(stringify(returnData)) which seems redundant since the data is immediately stringified and then parsed back. This pattern, combined with the existing bigNumberReplacer on line 99, raises several concerns:

  1. Double processing: Both bigNumberReplacer and stringify/parse may be handling similar data transformations
  2. Performance overhead: The serialize-deserialize cycle adds unnecessary computational cost
  3. Potential conflicts: The two transformations might interfere with each other

Consider if this pattern is truly necessary or if one of these approaches would be better:

  • Use only bigNumberReplacer if it handles all required transformations
  • Use only stringify if it's more comprehensive than bigNumberReplacer
  • Apply transformations in a single pass

Let me verify what the stringify function does and if this pattern is commonly used:


🏁 Script executed:

#!/bin/bash
# Search for similar stringify/parse patterns in the codebase
rg -A 2 -B 2 "JSON\.parse.*stringify"

# Search for other usages of the stringify utility
rg -A 5 -B 2 "stringify.*from.*thirdweb"

# Search for bigNumberReplacer usage patterns
rg -A 3 -B 3 "bigNumberReplacer"

Length of output: 9739


Review JSON serialization in read.ts

It looks like we first run returnData = bigNumberReplacer(returnData) and then immediately do

result: JSON.parse(stringify(returnData)) as any

– a pattern also used in get-receipt.ts and admin/transaction.ts to deep-clone and sanitize outputs. Since stringify from thirdweb/utils already applies its own BigNumber/BigInt replacer, this double handling may be redundant and adds extra CPU cost.

Please consider one of the following:

  • Drop the explicit bigNumberReplacer call and rely solely on stringify’s built-in replacer.
  • Or skip the JSON.parse(stringify(...)) step and send returnData directly after running bigNumberReplacer.
  • If both steps are required for edge cases, add a comment explaining why.

Location to update:
src/server/routes/contract/read/read.ts, line 103 (result: JSON.parse(stringify(returnData)) as any)

🤖 Prompt for AI Agents
In src/server/routes/contract/read/read.ts at line 103, the code redundantly
applies bigNumberReplacer to returnData before using stringify from
thirdweb/utils, which already handles BigNumber/BigInt serialization. To fix
this, remove the explicit bigNumberReplacer call and rely solely on stringify's
built-in replacer, then keep the JSON.parse(stringify(returnData)) step for deep
cloning and sanitization. Alternatively, if you prefer to keep both steps, add a
clear comment explaining why both are necessary to avoid confusion.

@d4mr d4mr merged commit 60d9d97 into main Aug 8, 2025
8 checks passed
@d4mr d4mr deleted the pb/contract-read-bigint-serialisation branch August 8, 2025 02:24
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.

3 participants