Todas as lições · Developer tooling · Começa aqui · Glossário
Use BigInt for uint64 RPC quantitiesPráticoDe uma correção
De uma correção · Verificação: certa · Verificada em 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.
Porque importa: 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.
Padrão
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)}`Um teste mudou no mesmo commit
Está ao lado da correcção. Nós não o corremos.
- Hanssen0-Alter-Ego/ckb-vm-js:
tests/browser/workbench.spec.js,tests/js/workbench.test.js
- Conceitos
- Data encoding (molecule, hex, bigints)
- Evidência
- De uma correção: de um projeto, verificada contra o commit
- Vista pela primeira vez
- 2026-11-16
- Última mudança
- 2026-11-16
- Última verificação
- 2026-11-19
- Verificação contra o commit
- certa: a lição sai do commit e continua a valer no código de hoje
Fontes (1)
- 2026-11-16 · Hanssen0-Alter-Ego/ckb-vm-js · mais deste projeto
Mais sobre 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
Manténs um projeto de onde esta lição veio? Confirma ou corrige
Citar esta lição
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.