全部经验 · Developer tooling · 从这里开始 · 术语表
Use BigInt for uint64 RPC quantities实践来自一次修复
来自一次修复 · 核对结果:正确 · 核对于 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.
为什么重要: 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.
代码模式
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)}`同一提交中改动了测试
它与修复在一起,我们没有运行它。
- Hanssen0-Alter-Ego/ckb-vm-js:
tests/browser/workbench.spec.js,tests/js/workbench.test.js
- 概念
- Data encoding (molecule, hex, bigints)
- 证据
- 来自一次修复: 来自一个项目,已对照其提交核对
- 首次出现
- 2026-11-16
- 最近改动
- 2026-11-16
- 最近核对
- 2026-11-19
- 对照提交的核对结果
- 正确:这条经验出自该提交,并且在今天的代码中仍然成立
来源(1)
- 2026-11-16 · Hanssen0-Alter-Ego/ckb-vm-js · 这个项目的更多经验
更多关于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
引用这条经验
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.