CKB Pulse
经验

CKB 学到了什么

从这里开始 · 术语表 · 自测 · 订阅

经验用英文撰写,请用英文搜索。

“Indexer queries and cell collection”

找到 43 条经验。 全部经验

第 1 页,共 4 页

Indexer get_cells order is by script args, not by cell age实践来自一次修复

Cells returned by a prefix search on type script args (as findRounds does here) come back in indexer key order, sorted by type args, not by creation time, so taking the first result does not give the newest cell. To get the latest, sort by a field stored in the cell (here the round config's entryStart).

#Indexer queries and cell collection · 来源(1) · 2026-11-09

Verifying an indexer funding cell against an advancing tip instead of a frozen snapshot实践来自一次修复

A frozen-tip check ("the indexer tip must not change during the scan") fails often on a live chain, so do not demand it. Select a single funding cell from get_cells, verify it directly against the node (get_live_cell, get_transaction, get_header, output and data equal to the indexed ones), then re-check at the end that get_block_hash at the starting indexer tip still equals the anchor hash, that the cell's block is canonical, and that the cell is still live. New blocks arriving in between are fine, but still fail closed if the indexer lags the node at the start or the anchor hash changed. This gives one verified input, not a snapshot of the whole wallet.

#Indexer queries and cell collection #Network and RPC reliability · 来源(1) · 2026-11-09

Wait for get_indexer_tip to reach the commit block before re-reading cells实践再次出现

After get_transaction reports tx_status committed, poll get_indexer_tip until its block_number is at least the transaction's block number before calling get_cells. If you query first, the indexer silently returns the pre-transaction cell set with no error.

#Indexer queries and cell collection #Network and RPC reliability · 来源(4) · 2026-11-09

Indexer free cell discovery by block scan plus get_live_cell on a local chain实践来自一次修复

Without an indexer on a small local chain, cells for a lock can be found by walking get_block_by_number from 0 to the tip, matching output locks, and confirming each hit with get_live_cell (with_data true). The commit also checks get_block_hash per height and at the end, then rechecks each match, so the result is treated as a snapshot that a reorg or spend can invalidate.

#Indexer queries and cell collection #Testing and devnet · 来源(2) · 2026-11-05

Paging indexer get_cells and get_transactions with last_cursor实践来自一次修复

The built-in indexer RPCs get_cells and get_transactions return at most the requested limit (here 0x3e8) plus a last_cursor. To read all results for a search key, pass last_cursor as the fourth param on the next call and stop once a page returns fewer objects than the limit; a single call with a small limit (the old 0xc8 or 0x19) undercounts cells and transactions.

#Indexer queries and cell collection #Network and RPC reliability · 来源(1) · 2026-10-30

Use indexer matched cell indexes to limit input parent fetches实践来自一次修复

With CCC client.findTransactionsPaged (scriptSearchMode 'prefix', groupByTransaction: true), each returned transaction has a cells list of {isInput, cellIndex} entries for the cells that matched the searched script. If your logic only needs the matched inputs, fetch parent transactions with getTransaction only for those indexes (plus siblings from a parent you already hold) and skip unrelated inputs such as wallet funding. OpenSwap's market scanner did this together with raising read concurrency to 16, and its first scan went from about 8 to 10 s to about 5.3 s; the gain from this change alone was not measured.

#Indexer queries and cell collection #Network and RPC reliability · 来源(1) · 2026-10-29

Finding cells of a ckb_js_vm JS contract needs a second indexer prefix search实践来自一次修复

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.

#Indexer queries and cell collection #Data encoding (molecule, hex, bigints) · 来源(1) · 2026-10-25

Reconstructing the live cell set at a past height from the CKB indexer进阶来自一次修复

The indexer's get_cells lists only cells live at its current tip. To get Nervos DAO deposits live at height H, read the indexer tip, list get_cells and keep those with block_number <= H, then read the indexer tip again as T. Then query get_transactions on the DAO type script with filter block_range [H+1, T+1) (the end is exclusive), keep io_type input, follow each input's previous_output to the creating tx and its header, and add back cells created at or below H. In both passes keep only real deposits (DAO type and 8 zero bytes of data), since withdrawing cells share the type script, and retry if either tip hash is no longer canonical per get_block_hash.

#Indexer queries and cell collection #Network and RPC reliability · 来源(1) · 2026-10-08

Use findCellsOnChain, not findCells, for block range queries in CCC实践由所有者核对

In CCC, client.findCells merges the client's local cache of cells it has sent, and its search key takes no blockRange filter. To list live cells created in a block range, call client.findCellsOnChain with filter.blockRange set to [from, to), where the end is exclusive. This queries the indexer directly.

#Indexer queries and cell collection · 来源(1) · 2026-09-25

Indexer RPC module must be listed in ckb.toml rpc modules for get_cells on devnet实践来自一次修复

CKB serves get_cells, get_indexer_tip and the other indexer RPC methods only when "Indexer" is listed in the [rpc] modules array of ckb.toml. The ckb.toml generated in the nervos/ckb 0.209.0 devnet image used here leaves Indexer out, so add it before relying on cell collection against a devnet node. Then confirm with a real indexer call such as get_cells after the node starts.

#Indexer queries and cell collection #Testing and devnet · 来源(1) · 2026-09-18

Never pass the terminal "0x" cursor back to indexer get_cells实践来自一次修复

An exhausted indexer get_cells scan returns {objects: [], last_cursor: "0x"} (captured from a real node). The authors report that calling get_cells again with after = "0x" then returns nothing, even once matching cells exist, and a hand-written mock that never returned the real "0x" hid this for days. When paging, stop on an empty page before reading last_cursor, and never send or persist a "0x" cursor. Build paging tests from captured node responses, not hand-written mocks.

#Indexer queries and cell collection #Testing and devnet · 来源(1) · 2026-09-18

Resolving cell deps per cell after redeploying a data-hashed script实践来自一次修复

After a data/data1 type script is redeployed with a new code hash, old cells still run against the old code. Keep a list of retired deployments and query the indexer for every one. Pick each cell's cell dep by matching the codeHash and hashType of that cell's own type script, not a single 'current' manifest entry.

#Cell deps and script lookup #Type ID and upgrades #Indexer queries and cell collection · 来源(1) · 2026-11-17

第 1 页,共 4 页

文本采用 CC BY 4.0:请署名 LusoCryptoLabs, CKB lessons,并附上经验的链接。 JSON · 想修改或撤下某条经验?请提交 issue。