CKB Pulse
Lessons

What CKB learned

Start here · Glossary · Test yourself · Feed

“Data encoding (molecule, hex, bigints)”

44 lessons found. All lessons

Page 3 of 4

Nervos DAO compensation from the header's accumulated rate (AR)WorkingSeen again

The DAO accumulated rate AR is the second little-endian u64 (bytes 8..16) of a header's `dao` field, for example from `get_header_by_number`. Interest accrues only on free = capacity minus occupied capacity, so compensation = free * AR_end / AR_deposit minus free, and the maximum withdraw is occupied + free * AR_end / AR_deposit. AR_deposit is the AR of the deposit block; AR_end is the AR of the block holding the withdrawing cell (phase 1) once withdrawal was requested, and only for a not yet withdrawn deposit is the tip AR used, as an estimate that is still growing.

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

Do not detect DER signatures by a leading 0x30 byteWorkingFrom one fix

When converting secp256k1 signatures to DER for a CKB contract (here the Perun channel script, which uses k256 and expects low-S), a 64 or 65 byte compact R||S(||V) signature can begin with 0x30 because R is arbitrary. Dispatch on the fixed lengths first, and parse anything else with a full asn1.Unmarshal that has no trailing bytes, followed by a check that R and S lie in [1, n).

#Witnesses and signatures #Data encoding (molecule, hex, bigints) · Sources (1) · 2026-11-10

Handle None from ckb_sdk Since::extract_metric for invalid since valuesWorkingFrom one fix

A raw since u64 can carry the reserved metric flag 0b11 (e.g. 0x6000_0000_0000_0000), for which ckb_sdk::Since::extract_metric() returns None, and a timestamp metric value can exceed what chrono can represent. Code that formats since values received from RPC should handle both cases instead of unwrapping, as ckb-cli now does by printing "invalid since" or "invalid".

#Since and time locks #Data encoding (molecule, hex, bigints) · Sources (1) · 2026-11-09

Parsing snake_case JSON-RPC transactions in CCCWorkingReproduced

ccc.Transaction.from reads only camelCase keys, so a snake_case JSON-RPC transaction (such as the ones ckb-cli writes, with cell_deps, outputs_data and similar) has to be converted with cccA.JsonRpcTransformers.transactionTo from @ckb-ccc/core/advanced. Passing that JSON directly to Transaction.from does not read those fields.

#Data encoding (molecule, hex, bigints) #Transaction building and fees · Sources (1) · 2026-11-08

Shape of ckb-cli deploy sign-txs outputWorkingFrom one fix

`ckb-cli deploy sign-txs` prints two maps, `cell_tx_signatures` and `dep_group_tx_signatures`, for the deploy info file's `cell_tx` and `dep_group_tx`. Each map goes from lock args (20 bytes, or 28 for multisig args with a since) to one 65 byte signature. It prints YAML-style text by default and a JSON object with `--output-format json`, and the YAML writer prints an empty map inline as `cell_tx_signatures: {}`, so a parser collecting multisig signatures must accept both shapes and the inline empty header.

#Witnesses and signatures #Data encoding (molecule, hex, bigints) · Sources (1) · 2026-11-08

Reading total occupied capacity (U) from the header DAO fieldWorkingFrom one fix

The block header `dao` field packs four little endian u64 values (C, AR, S, U), and U at byte offset 24 is the total occupied capacity of all live cells in shannons. This commit reads it from `get_tip_header` to show chain state size, and for a genesis that holds the 8.4 billion CKB cell (mainnet and offckb devnet) it subtracts 5.04 billion CKB counted as occupied because it is due to be burnt, as the CKB Explorer does.

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

Finding cells of a ckb_js_vm JS contract needs a second indexer prefix searchWorkingFrom one fix

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) · Sources (1) · 2026-10-25

Omnilock owner signing needs an 85 byte zeroed witness lock placeholderWorkingFrom one fix

For an Omnilock cell spent in owner (secp256k1) mode, the WitnessArgs.lock is an 85 byte OmniLockWitnessLock (a 20 byte molecule header 0x5500000010000000550000005500000041000000 plus the 65 byte signature), so the sighash digest must be computed with an 85 byte zeroed placeholder (e.g. CCC prepareSighashAllWitness(lock, 85, client)). A digest taken over the usual 65 byte secp256k1 placeholder does not verify, which the test confirms against a real testnet spend.

#Witnesses and signatures #Data encoding (molecule, hex, bigints) · Sources (2) · 2026-10-23

Recognizing a Nervos DAO deposit cell (not a withdrawing one)WorkingSeen again

Treat a cell as a Nervos DAO deposit only if its type script exactly matches the DAO type script and its data is exactly 8 zero bytes. The DAO type script has code hash 0x82d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e, hash_type type and empty args. A phase one withdrawing cell has the same type script but a nonzero block number in its 8 data bytes, so it fails this check, as do data of any other length and look alike type scripts.

joined with the ckb-service-runner card teaching the same check

#Indexer queries and cell collection #Data encoding (molecule, hex, bigints) · Sources (2) · 2026-10-20

Transaction size for fee rate is serialized bytes plus 4WorkingFrom one fix

To get a transaction's size as the node counts it, take the molecule serialized size of the full transaction with witnesses (for example ccc.Transaction.from(...).toBytes().length) and add 4 bytes for its offset in the block. A size-based fee rate is fee * 1000 / size in shannons per 1000 bytes; the node's pool actually uses weight, the larger of size and cycles scaled, so it can be higher for cycle-heavy transactions. get_transaction returns snake_case JSON, so map the fields (code_hash to codeHash, dep_type dep_group to depGroup) before passing it to ccc.Transaction.from.

#Transaction building and fees #Data encoding (molecule, hex, bigints) · Sources (1) · 2026-10-17

Address balance via get_cells_capacity with snake_case lock scriptWorkingFrom one fix

To show a CKB address balance, convert the address to a lock script (ckb-sdk-utils addressToScript returns camelCase codeHash/hashType) and pass it to the indexer RPC get_cells_capacity with snake_case fields (code_hash, hash_type, args) and script_type "lock". The returned capacity is a hex shannon string, so parse it with BigInt and divide by 10^8 for CKB.

#Indexer queries and cell collection #Data encoding (molecule, hex, bigints) · Sources (1) · 2026-10-15

Convert Fiber RPC snake_case scripts to CCC camelCase ScriptLikeWorkingReproduced

Fiber RPC returns scripts as { code_hash, hash_type, args }, but CCC's ScriptLike expects { codeHash, hashType, args }. In this commit a Fiber shaped lock was passed to a CCC based sweep as if it were a ccc.ScriptLike and the sweep failed, so map the fields explicitly before handing the script to CCC.

#Data encoding (molecule, hex, bigints) #Channels and payments · Sources (1) · 2026-10-14

Page 3 of 4

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.