CKB Pulse

All lessons · CKB node, RPC and indexer · Start here · Glossary

Filter prefix get_cells results by data length before decodingWorkingFrom one fix

From one fix · Check: right · Checked 2026-11-19

A get_cells query with script_search_mode "prefix" and args "0x" returns every live cell whose script has that code hash and hash_type, whatever its args, so it can include cells of the same script with a different data layout (for example a script that owns both a state cell and a ledger cell). Check output_data length, or catch the decode error, and skip the cell before calling a strict decoder. Otherwise one unexpected cell throws and the whole result list is lost.

Why it matters: Without the length check one cell with a different data length makes the strict decoder throw, and the page shows no rounds at all instead of the rounds that exist.

Pattern

Prefer
if (data.length !== ROUND_CONFIG_SIZE) continue; // not a round config cell

Taken from the commit, shortened.

A test changed in the same commit

It sits next to the fix. We did not run it.

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-09-18
Last changed
2026-09-18
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, "Filter prefix get_cells results by data length before decoding", CKB lessons, https://pulse.lusocryptolabs.com/learned/node/filter-prefix-get-cells-results-by-data-length-before-decodi, CC BY 4.0, last changed 2026-09-18.

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.