Skip to content

fix: serialize BigInt values in social login RPC requests - #5632

Merged
svenvoskamp merged 1 commit into
chore/khizr-fixesfrom
chore/khizr-fixes-REOWN-4455
Apr 13, 2026
Merged

fix: serialize BigInt values in social login RPC requests#5632
svenvoskamp merged 1 commit into
chore/khizr-fixesfrom
chore/khizr-fixes-REOWN-4455

Conversation

@Khizr97

@Khizr97 Khizr97 commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes Magic RPC Error [-32603] Do not know how to serialize a BigInt when sending transactions via social login (REOWN-4455).

Technical Report

Problem

When a user connects via social login (Magic) and sends any transaction, it fails with "Do not know how to serialize a BigInt". Only social login is affected — MetaMask, WalletConnect, and injected wallets work fine.

Root Cause Analysis

W3mFrameProvider.request() passes RPC payloads to the Magic iframe via postMessage(). The browser's structured cloning algorithm (used by postMessage) cannot serialize BigInt values. The wagmi adapter creates transaction params with BigInt values at lines 432-434 of client.ts (BigInt(params.value), BigInt(params.gas), BigInt(params.gasPrice)). These BigInt values flow through to the postMessage call at W3mFrame.ts:242.

Other wallets aren't affected because they use different transport mechanisms that handle BigInt natively (direct provider calls, not iframe postMessage).

Approach & Reasoning

Added serializeBigInts() helper that recursively converts BigInt values to 0x-prefixed hex strings before the payload reaches postMessage. Applied at the single convergence point — W3mFrameProvider.request() — so all RPC methods are covered.

Why 0x hex strings: This is the standard Ethereum JSON-RPC encoding for quantities (gas, value, nonce). The Magic iframe expects this format.

Why recursive: RPC params can be nested objects/arrays (e.g., sendTransaction params contain objects with gas, value fields). The helper traverses the full structure.

Immutability: The helper creates new objects/arrays — the original request is not mutated. This is important because the original request is also passed to rpcSuccessHandler/rpcErrorHandler downstream.

Considered alternatives:

  • Fixing at the wagmi adapter level (converting BigInt before passing to provider) — would only fix wagmi, not ethers or direct provider.request() calls
  • Patching postMessage to add BigInt support — not possible, browser API limitation
  • The chosen approach fixes at the single point where all RPC requests converge before hitting the iframe

Edge Cases

  • BigInt(0) → "0x0" (correct)
  • Very large BigInts → full hex string (correct)
  • Negative BigInts → "0x-1" (invalid but never occurs in Ethereum RPC — gas/value/nonce are unsigned)
  • null/undefined/strings/numbers → passed through unchanged

Verification

  • 27/27 wallet package tests pass
  • Type check clean
  • Only affects W3mFrameProvider (social login) — no impact on other wallet types

Test plan

  • Connect via social login (Google)
  • Send a transaction (e.g. ERC20 approve) — should succeed
  • Verify MetaMask/WalletConnect transactions still work

🤖 Generated with Claude Code

Magic provider uses postMessage to communicate with its iframe, which
cannot handle BigInt values via structured cloning. This caused
"Do not know how to serialize a BigInt" errors when sending transactions
via social login (Google, etc). Added serializeBigInts() helper that
recursively converts BigInt values to 0x-prefixed hex strings before
passing RPC requests to the iframe.

Closes REOWN-4455

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@linear

linear Bot commented Apr 9, 2026

Copy link
Copy Markdown

@changeset-bot

changeset-bot Bot commented Apr 9, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: ee4a562

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CTA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@vercel

vercel Bot commented Apr 9, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
appkit-demo Ready Ready Preview, Comment Apr 9, 2026 1:25pm
appkit-gallery Ready Ready Preview, Comment Apr 9, 2026 1:25pm
appkit-headless-sample-app Ready Ready Preview, Comment Apr 9, 2026 1:25pm
appkit-laboratory Ready Ready Preview, Comment Apr 9, 2026 1:25pm
9 Skipped Deployments
Project Deployment Actions Updated (UTC)
appkit-basic-example Ignored Ignored Apr 9, 2026 1:25pm
appkit-basic-sign-client-example Ignored Ignored Apr 9, 2026 1:25pm
appkit-basic-up-example Ignored Ignored Apr 9, 2026 1:25pm
appkit-ethers5-bera Ignored Ignored Apr 9, 2026 1:25pm
appkit-nansen-demo Ignored Ignored Apr 9, 2026 1:25pm
appkit-wagmi-cdn-example Ignored Ignored Apr 9, 2026 1:25pm
ethereum-provider-wagmi-example Ignored Ignored Apr 9, 2026 1:25pm
next-wagmi-solana-bitcoin-example Ignored Ignored Apr 9, 2026 1:25pm
vue-wagmi-example Ignored Ignored Apr 9, 2026 1:25pm

Request Review

@svenvoskamp

Copy link
Copy Markdown
Contributor

Does this influence other clients like Ethers?

@Khizr97

Khizr97 commented Apr 13, 2026

Copy link
Copy Markdown
Contributor Author

I have read the CTA Document and I hereby sign the CTA

@svenvoskamp
svenvoskamp merged commit 13f225f into chore/khizr-fixes Apr 13, 2026
17 of 18 checks passed
@svenvoskamp
svenvoskamp deleted the chore/khizr-fixes-REOWN-4455 branch April 13, 2026 16:28
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants