CKB Pulse

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

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

More about CKB node, RPC and indexer

All 45 in this topic

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.

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.