All lessons · Rust scripts and ckb-std · Start here · Glossary
Iterating group inputs and outputs with ckb-std until IndexOutOfBoundWorkingFrom one fix
From one fix · Check: right · Checked 2026-11-19
In a ckb-std script, walk the cells of a source with the high-level loaders, for example load_cell_type_hash(i, Source::GroupInput) or load_cell_lock_hash(j, Source::Output), in an index loop. Break on Err(SysError::IndexOutOfBound), and return a script error code for any other SysError. Accumulate the u64 capacities you load in a u128 so that a sum over many cells cannot overflow.
Why it matters: Without the IndexOutOfBound break the loop has no clean end condition, and treating every load error as the end of the list would hide real syscall failures.
Pattern
Err(SysError::IndexOutOfBound) => break,Taken from the commit, shortened.
A test changed in the same commit
It sits next to the fix. We did not run it.
- salmansarwarr/Tranfr:
sdk/tests/client.test.ts,sdk/tests/scaffold.test.ts,tests/src/tests.rs
- Concepts
- Capacity and cell size, Cell deps and script lookup
- Evidence
- From one fix: from one project, checked against its commit
- First seen
- 2026-11-08
- Last changed
- 2026-11-08
- 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-11-08 · salmansarwarr/Tranfr · more from this project
More about Rust scripts and ckb-std
- Minimum capacity of a cell depends on its lock args length
- Check that a derived successor type args match the spent cell's type args
- Cheque lock receiver path must return the cell's capacity to the sender
Do you maintain a project this lesson came from? Confirm or correct it
Cite this lesson
LusoCryptoLabs, "Iterating group inputs and outputs with ckb-std until IndexOutOfBound", CKB lessons, https://pulse.lusocryptolabs.com/learned/scripts/iterating-group-inputs-and-outputs-with-ckb-std-until-indexo, CC BY 4.0, last changed 2026-11-08.