CKB Pulse
Lessons

What CKB learned

Start here · Glossary · Test yourself · Feed

Apps and UI

9 lessons found. All lessons

Resolving cell deps per cell after redeploying a data-hashed scriptWorkingFrom one fix

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 · Sources (1) · 2026-11-17

Saving local state after the first step of a multi-step flowWorkingFrom one fix

In flows like Create followed by Arm, save local state right after the first transaction is sent. If you wait until the whole flow finishes, a failure in a later step leaves an on-chain object the user cannot find or cancel. Add the extra fields, such as the descriptor, once the later steps succeed.

#Transaction building and fees #Other · Sources (1) · 2026-11-16

Exact CKB-to-shannon conversion with BigIntWorkingFrom one fix

Convert user-entered CKB amounts to shannons with BigInt string arithmetic: BigInt(whole) * 100000000n + BigInt(fraction.padEnd(8, '0')). Never use parseFloat(amount) * 1e8. First validate the input with /^\d+(\.\d{1,8})?$/, which rejects exponents, hex and commas, and reject any result above u64::MAX (0xffffffffffffffffn).

#Data encoding (molecule, hex, bigints) #Capacity and cell size · Sources (1) · 2026-11-15

Lock-based fallback when a stored out point goes staleWorkingFrom one fix

A saved out point stops being valid once the cell is consumed and recreated. Use the recorded out point if it is still live; otherwise find the unique live cell matching the exact lock (code_hash, hash_type, args). In both cases, still check the cell's contents against the recorded values.

#Indexer queries and cell collection · Sources (1) · 2026-11-15

Witness data in input_type and folding sub-minimum changeWorkingFrom one fix

Put the type script's witness data in WitnessArgs.input_type of each input it guards (the type script reads the first witness of its own input group), so the lock field stays free for the wallet's signature and one signature can cover several such inputs. If the change left after a fixed fee is below a plain cell's minimum occupied capacity, add it to an existing output whose scripts accept extra capacity; if there is no such output, refuse the build instead of creating a cell that cannot exist.

#Witnesses and signatures #Transaction building and fees #Capacity and cell size · Sources (1) · 2026-11-14

Nervos DAO hold time with term-locked withdrawalsWorkingFrom one fix

The Nervos DAO pays out phase 2 only at a whole number of 180-epoch cycles counted from the deposit epoch D, so a withdrawal started after D + 180×n matures at D + 180×(n+1). If a lock refuses phase 1 until a term of n cycles has passed, then in practice the funds are held (n + 1) × 180 epochs, not n × 180, and interest stops at the phase 1 block. Only a phase 1 that lands exactly in the boundary epoch fraction avoids the extra cycle.

#Since and time locks #Other · Sources (1) · 2026-11-13

Pinning JS codecs and derivations to Rust test vectorsWorkingFrom one fix

When off-chain JS encodes or derives cell data that a Rust type script decodes or re-derives byte for byte, test the JS against JSON vectors generated by the Rust code, using a distinct value in every field so a wrong offset fails. Mirror the contract's validation refusals and its exact ordering and rounding: BTreeMap ascending key order, BigInt floor division with the dust going to fixed indices, and merging duplicates before dividing. The chain only returns a bare error code, so only this off-chain check can tell you which rule failed.

#Data encoding (molecule, hex, bigints) #Testing and devnet #Transaction building and fees · Sources (2) · 2026-11-13

Pre-sign checkers must mirror every on-chain comparisonWorkingFrom one fix

A pre-sign checker that reuses the builder's assumptions will miss the builder's bugs, so make it compare every field the script compares, outputs_data included. When you add data to an output, count those bytes in its occupied capacity (8 + data + lock + type). Replay refused transactions in ckb-debugger against the deployed binaries to confirm the fix.

#Capacity and cell size #Transaction building and fees #Testing and devnet · Sources (1) · 2026-11-11

Occupied capacity depends on the actual lock's args lengthWorkingFrom one fix

When quoting the capacity for cells locked to a user's wallet, compute the occupied size from the connected lock script (8 capacity bytes + 32 code_hash + 1 hash_type + args length + type + data), not a hardcoded value. In this commit a JoyID lock with 22 byte args gives a 222 CKB claim cell and a secp256k1 lock with 20 byte args gives 220 CKB. The script's molecule serialization header does not count toward occupied capacity.

Distinct from the pre-sign checker lesson: this is about sizing by the connected lock's real args length.

#Capacity and cell size · Sources (1) · 2026-09-23

Text under CC BY 4.0: credit LusoCryptoLabs, CKB lessons, with a link to the lesson. JSON · Want a lesson changed or removed? Open an issue.