fix(sdk): Add proper BigInt serialization for JSON API responses - #258
Merged
Kevin737866 merged 2 commits intoSep 4, 2026
Merged
Conversation
JSON.stringify throws on bigint. Adds first-class BigInt <-> JSON support:
- bigIntReplacer: JSON.stringify replacer rendering every bigint (and
bignumber.js-like objects) as a decimal string - for external API
responses
- serializeBigInts(value): deep, non-mutating conversion of every bigint
to a string across nested objects, arrays, Map and Set
- taggedBigIntReplacer / bigIntReviver + stringifyJSON / parseJSON:
lossless round-trip via a {"$bigint":"<decimal>"} tag
- createBigIntReviver(keys, { onlyUnsafe? }): reviver that restores
BigInt for known field names from plain-string output
- isTaggedBigInt / BIGINT_TAG / TaggedBigInt helpers
- StellarRWASDK.toJSONSafe() / .stringifyJSON() / .parseJSON() so every
client's results serialize consistently
Files:
- sdk/src/types.ts
- sdk/src/index.ts
Closes Kevin737866#193
|
@Vincent6581 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Owner
|
@Vincent6581 conflict |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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
JSON.stringifythrowsTypeError: Do not know how to serialize a BigInt. This adds first-class BigInt ⇄ JSON support, per issue #193.Acceptance criteria
bigIntReplacer/serializeBigInts()render everybigintas a decimal stringbigIntReviver(tagged) andcreateBigIntReviver(keys)(plain strings by field name)bigIntReplacer,taggedBigIntReplacer,bigIntReviver,createBigIntReviverStellarRWASDK.toJSONSafe()/.stringifyJSON()/.parseJSON()— one path all client results flow throughTwo modes
Plain-string — for external APIs where big integers are strings:
Tagged (lossless round-trip) — for caches / persistence:
Round-trips correctly through nested objects and arrays (negative values and values beyond
Number.MAX_SAFE_INTEGERincluded).Restoring from plain strings when you know the schema
Files changed
sdk/src/types.ts— replacers, revivers,serializeBigInts,stringifyJSON/parseJSON,BIGINT_TAG/TaggedBigInt/isTaggedBigIntsdk/src/index.ts— re-exports +StellarRWASDK.toJSONSafe()/.stringifyJSON()/.parseJSON()Closes #193