All lessons · Wallets and signing · Start here · Glossary
Address balance via get_cells_capacity with snake_case lock scriptWorkingFrom one fix
From one fix · Check: right · Checked 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.
Why it matters: 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.
Pattern
script: { code_hash: lock.codeHash, hash_type: lock.hashType, args: lock.args },Taken from the commit, shortened.
- Concepts
- Indexer queries and cell collection, Data encoding (molecule, hex, bigints)
- Evidence
- From one fix: from one project, checked against its commit
- First seen
- 2026-10-15
- Last changed
- 2026-10-15
- 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-10-15 · salmansarwarr/Kirea-finance · more from this project
More about 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
Do you maintain a project this lesson came from? Confirm or correct it
Cite this lesson
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.