CKB Pulse

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.

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)

More about Developer tooling

All 35 in this topic

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.

Drawn from public commits and checked against the commit each one came from and the project's code today. Read the source before you rely on one. Text under CC BY 4.0: credit LusoCryptoLabs, CKB lessons, with a link to the lesson. Want a lesson changed or removed? Open an issue.