CKB Pulse

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

Prefer
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)

More about Wallets and signing

All 23 in this topic

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.

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.