Skip to content

BigInt values cannot be serialized to JSON #363

@Radiiplus

Description

@Radiiplus

Description

The CCC library returns BigInt values from chain queries, but JavaScript's JSON.stringify() doesn't support BigInt, causing serialization failures.

Error

TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)

Reproduction

const launchData = await getLaunchFromChain(launchId);
// launchData.targetCkb is a BigInt
JSON.stringify(launchData); // Throws error

Expected Behavior

The library should either:

  1. Provide built-in serialization helpers (e.g., launchData.toJSON())
  2. Return string-encoded values by default
  3. Document the required conversion pattern

Impact

Developers must manually convert every BigInt field before saving or transmitting data, which is error-prone and inconsistent.

Temporal Workaround

JSON.stringify({
  targetCkb: launchData.targetCkb.toString(),
  // ... every field
});

Request

Please provide a standard serialization/deserialization pattern for BigInt values in the library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions