From ee4a56238884824beb4b859e3adbad12b106bf49 Mon Sep 17 00:00:00 2001 From: Khizr Reown Date: Thu, 9 Apr 2026 18:20:19 +0500 Subject: [PATCH] fix: serialize BigInt values in social login RPC requests 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) --- packages/wallet/src/W3mFrameProvider.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/wallet/src/W3mFrameProvider.ts b/packages/wallet/src/W3mFrameProvider.ts index 94e995f887..f587101df7 100644 --- a/packages/wallet/src/W3mFrameProvider.ts +++ b/packages/wallet/src/W3mFrameProvider.ts @@ -15,6 +15,28 @@ import type { W3mFrameTypes } from './W3mFrameTypes.js' type AppEventType = Omit +// -- Helpers ---------------------------------------------------------------- +function serializeBigInts(value: T): T { + if (typeof value === 'bigint') { + return `0x${value.toString(16)}` as unknown as T + } + + if (Array.isArray(value)) { + return value.map(serializeBigInts) as unknown as T + } + + if (value !== null && typeof value === 'object') { + const result: Record = {} + for (const [k, v] of Object.entries(value)) { + result[k] = serializeBigInts(v) + } + + return result as T + } + + return value +} + interface W3mFrameProviderConfig { projectId: string chainId?: W3mFrameTypes.Network['chainId'] @@ -541,7 +563,7 @@ export class W3mFrameProvider { this.rpcRequestHandler?.(req) const response = await this.appEvent<'Rpc'>({ type: W3mFrameConstants.APP_RPC_REQUEST, - payload: request + payload: serializeBigInts(request) } as W3mFrameTypes.AppEvent) this.rpcSuccessHandler?.(response, request)