JSON.stringify that emits bigint values as exact JSON number literals.
A u64 above Number.MAX_SAFE_INTEGER cannot survive a trip through a
JavaScript number — Number(9007199254740993n) is 9007199254740992 — so a
transaction body built that way no longer matches the transaction the caller
signed. Keeping the value a bigint all the way to serialization avoids the
lossy conversion, and writing it as a bare number literal keeps the wire
format byte-identical to what the RPC already accepts (Rust's serde_json
parses u64/u128 from number literals without going through a float).
Every other value is serialized exactly as JSON.stringify would, so the
output for a bigint-free input is unchanged.
Parameters
value: unknown
The value to serialize.
Returns string
The JSON text, with any bigint written as an exact number literal.
Throws
If value is not JSON-serializable, or if a string inside value
collides with the internal marker — the serializer fails closed rather than
emitting a number the caller never supplied.
JSON.stringifythat emitsbigintvalues as exact JSON number literals.A
u64aboveNumber.MAX_SAFE_INTEGERcannot survive a trip through a JavaScriptnumber—Number(9007199254740993n)is9007199254740992— so a transaction body built that way no longer matches the transaction the caller signed. Keeping the value abigintall the way to serialization avoids the lossy conversion, and writing it as a bare number literal keeps the wire format byte-identical to what the RPC already accepts (Rust'sserde_jsonparsesu64/u128from number literals without going through a float).Every other value is serialized exactly as
JSON.stringifywould, so the output for a bigint-free input is unchanged.