diff --git a/yarn-project/foundation/src/json-rpc/convert.ts b/yarn-project/foundation/src/json-rpc/convert.ts index bcd5b15d3c7..53a3fe0d3b3 100644 --- a/yarn-project/foundation/src/json-rpc/convert.ts +++ b/yarn-project/foundation/src/json-rpc/convert.ts @@ -117,6 +117,14 @@ export function convertFromJsonObj(cc: ClassConverter, obj: any): any { * @returns The encoded object. */ export function convertToJsonObj(cc: ClassConverter, obj: any): any { + // Bigint is a primitive type that needs special handling since it's not serialisable + if (typeof obj === 'bigint') { + return { + type: 'bigint', + data: obj.toString(), + }; + } + if (!obj) { return obj; // Primitive type } @@ -126,13 +134,6 @@ export function convertToJsonObj(cc: ClassConverter, obj: any): any { return { type: 'Buffer', data: obj.toString('base64') }; } - if (typeof obj === 'bigint') { - return { - type: 'bigint', - data: obj.toString(), - }; - } - // Is this a convertible type? if (cc.isRegisteredClass(obj.constructor)) { return cc.toJsonObj(obj);