All lessons · Developer tooling · Start here · Glossary
Use BigInt for uint64 RPC quantitiesWorkingFrom one fix
From one fix · Check: right · Checked 2026-11-19
CKB RPC quantities such as max_cycles and max_block_cycles are uint64 hex strings, and Number or parseInt silently round anything above 2^53. When turning a decimal string a user typed into one, accept only /^[0-9]+$/, parse it with BigInt, reject n >= 1n<<64n, and format it as `0x${n.toString(16)}` (no leading zeros). To show an RPC hex value as decimal, use BigInt(hex).toString(10), never Number.
Why it matters: Routing a cycles value such as 9007199254740993 through Number silently changes it, so the request sends a different max_cycles than the user typed, and values near 2^64 cannot be expressed at all.
Pattern
Number(value).toString(16) / parseInt(hex) for uint64 RPC fields → validate with /^[0-9]+$/, BigInt(value), check n < 1n<<64n, then `0x${n.toString(16)}`A test changed in the same commit
It sits next to the fix. We did not run it.
- Hanssen0-Alter-Ego/ckb-vm-js:
tests/browser/workbench.spec.js,tests/js/workbench.test.js
- Concepts
- Data encoding (molecule, hex, bigints)
- Evidence
- From one fix: from one project, checked against its commit
- First seen
- 2026-11-16
- Last changed
- 2026-11-16
- Last checked
- 2026-11-19
- Check against the commit
- right: the lesson follows from its commit and still holds in the code today
Sources (1)
- 2026-11-16 · Hanssen0-Alter-Ego/ckb-vm-js · more from this project
More about Developer tooling
- ckb-vm-js 0.2.0 (npm) checks header hash instead of rejecting the field
- Matching a Script code_hash to its code Cell by hash_type
- Decoding InvalidDepGroup OutPoints
Do you maintain a project this lesson came from? Confirm or correct it
Cite this lesson
LusoCryptoLabs, "Use BigInt for uint64 RPC quantities", CKB lessons, https://pulse.lusocryptolabs.com/learned/tooling/use-bigint-for-uint64-rpc-quantities, CC BY 4.0, last changed 2026-11-16.