All lessons · CKB node, RPC and indexer · Start here · Glossary
Finding cells of a ckb_js_vm JS contract needs a second indexer prefix searchWorkingFrom one fix
From one fix · Check: right · Checked 2026-11-19
A cell that runs a JS contract carries the ckb_js_vm script as its lock or type. Its args are 2 flag bytes, then the contract's 32 byte code hash, then its hash type byte (data 0, type 1, data1 2, data2 4). A get_cells prefix search on the contract's own code_hash finds none of these cells, so also run a prefix search on the ckb_js_vm script with args set to flags plus code hash plus hash type byte, and merge the results. With 0x0000 as the flags, that search only matches cells whose flags are zero.
Why it matters: Without the second search, an explorer or indexer query reports zero live cells for every JS contract, even when many exist.
Pattern
prefixes.push({ code_hash: vm.codeHash, hash_type: vm.hashType, args: "0x0000" + s.codeHash.slice(2) + Number(byte).toString(16).padStart(2, "0") });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-25
- Last changed
- 2026-10-25
- 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-25 · wildanrhmn/ckb-devnet-explorer · more from this project
More about CKB node, RPC and indexer
- Nervos DAO phase 1 withdrawing cells keep the DAO type; count deposits by 8 zero bytes of data
- Filter prefix get_cells results by data length before decoding
- Check chain-wide script users before consuming a deployed code cell
Do you maintain a project this lesson came from? Confirm or correct it
Cite this lesson
LusoCryptoLabs, "Finding cells of a ckb_js_vm JS contract needs a second indexer prefix search", CKB lessons, https://pulse.lusocryptolabs.com/learned/node/finding-cells-of-a-ckb-js-vm-js-contract-needs-a-second-inde, CC BY 4.0, last changed 2026-10-25.