Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/server/routes/contract/read/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import type { AbiParameters } from "ox";
import { readContract as readContractV5, resolveMethod } from "thirdweb";
import { parseAbiParams } from "thirdweb/utils";
import { parseAbiParams, stringify } from "thirdweb/utils";
import type { AbiFunction } from "thirdweb/utils";
import { getContractV5 } from "../../../../shared/utils/cache/get-contractv5";
import { prettifyError } from "../../../../shared/utils/error";
Expand Down Expand Up @@ -100,7 +100,7 @@ export async function readContract(fastify: FastifyInstance) {

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.

});
},
});
Expand Down
Loading