Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/transactions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,20 @@ import { cvToJSON, hexToCV } from '@stacks/transactions';

cvToJSON(hexToCV(tx.tx_result.hex));
```
### Handling BigInt Serialization

When working with Stacks.js, you will frequently encounter native JavaScript `BigInt` values (e.g., transaction fees, token balances). Standard `JSON.stringify()` cannot serialize `BigInt` values and will throw a `TypeError: Do not know how to serialize a BigInt`.

To fix this, use a custom replacer function when stringifying your data:

```typescript
const data = {
amount: 12345n,
fee: 500n
};

// Use a replacer function to convert BigInt to string
const jsonString = JSON.stringify(data, (key, value) =>
typeof value === 'bigint' ? value.toString() : value
);
// Result: '{"amount":"12345","fee":"500"}'