fix: serialize BigInt values in social login RPC requests - #5632
Merged
Conversation
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>
|
Contributor
|
All contributors have signed the CTA ✍️ ✅ |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
9 Skipped Deployments
|
Contributor
|
Does this influence other clients like Ethers? |
Contributor
Author
|
I have read the CTA Document and I hereby sign the CTA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Edge Cases
Verification
Test plan
🤖 Generated with Claude Code