全部经验 · Wallets and signing · 从这里开始 · 术语表
Address balance via get_cells_capacity with snake_case lock script实践来自一次修复
来自一次修复 · 核对结果:正确 · 核对于 2026-11-19
To show a CKB address balance, convert the address to a lock script (ckb-sdk-utils addressToScript returns camelCase codeHash/hashType) and pass it to the indexer RPC get_cells_capacity with snake_case fields (code_hash, hash_type, args) and script_type "lock". The returned capacity is a hex shannon string, so parse it with BigInt and divide by 10^8 for CKB.
为什么重要: The node's JSON-RPC expects snake_case script fields, so passing the camelCase object that addressToScript returns gives an invalid params error and the balance lookup fails.
代码模式
script: { code_hash: lock.codeHash, hash_type: lock.hashType, args: lock.args },摘自提交,已缩短。
- 概念
- Indexer queries and cell collection, Data encoding (molecule, hex, bigints)
- 证据
- 来自一次修复: 来自一个项目,已对照其提交核对
- 首次出现
- 2026-10-15
- 最近改动
- 2026-10-15
- 最近核对
- 2026-11-19
- 对照提交的核对结果
- 正确:这条经验出自该提交,并且在今天的代码中仍然成立
来源(1)
- 2026-10-15 · salmansarwarr/Kirea-finance · 这个项目的更多经验
更多关于Wallets and signing
- Count only empty, typeless lock cells as spendable balance
- Do not detect DER signatures by a leading 0x30 byte
- Omnilock owner signing needs an 85 byte zeroed witness lock placeholder
引用这条经验
LusoCryptoLabs, "Address balance via get_cells_capacity with snake_case lock script", CKB lessons, https://pulse.lusocryptolabs.com/learned/wallets/address-balance-via-get-cells-capacity-with-snake-case-lock, CC BY 4.0, last changed 2026-10-15.