CKB Pulse
Lessons

What CKB learned

Start here · Glossary · Test yourself · Feed

“Other”

55 lessons found. All lessons

Page 4 of 5

Indexer free cell discovery by block scan plus get_live_cell on a local chainWorkingFrom one fix

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 · Sources (2) · 2026-11-05

One placeholder witness per input when all inputs share one lockWorkingFrom one fix

In this deploy builder, several funding inputs all share the owner's lock. The signing witness (WitnessArgs) goes at index 0, and every other input gets an empty "0x" witness, so the witnesses list stays as long as the inputs list. That matches the secp256k1 sighash script group layout, where the first witness of the group carries the signature and covers the rest.

#Witnesses and signatures #Transaction building and fees · Sources (1) · 2026-11-05

Minimum capacity of a cell depends on its lock args lengthWorkingChecked by the owner

A cell with no type and no data needs at least 8 (capacity) + 32 (code hash) + 1 (hash type) + args length in CKB: 61 CKB for a secp256k1_blake160 lock (20-byte args), 63 CKB for a JoyID lock with 22-byte args. A contract that knows a recipient lock only by hash cannot measure it, so a hardcoded floor for the fee output must be at least the largest lock it may face on each network, and a test should measure the real lock against it. Otherwise the fee output cannot be built.

#Capacity and cell size · Sources (2) · 2026-10-30

Use raw_data(), not as_slice(), when parsing a packed::Bytes witnessWorkingChecked by the owner

A transaction witness in ckb_types is a molecule packed::Bytes, so as_slice() returns the 4 byte length header followed by the content, while raw_data() returns only the content (here a serialized WitnessArgs). A check that compares a witness to the secp256k1 sighash placeholder WitnessArgs (lock of 65 zero bytes) must use witness.raw_data() (or unpack()), otherwise it is silently never true. Fiber's funding witness merge never recognized placeholders until it switched to raw_data(), so a peer's placeholder could be kept in place of a real signature.

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

Search for a script's cells under both its data hash and its type id code hashWorkingChecked by the owner

A script deployed with a type id can be referenced by cells either as hashType data1 with the code's data hash or as hashType type with the deployment's type id hash (per network). An exact indexer search via client.findCells over only one form misses the other; here @ckbfs/api's useTypeID cells read as missing until the reader queried both forms and treated a combined count above one as an error.

#Indexer queries and cell collection #Type ID and upgrades · Sources (1) · 2026-10-24

Keep at least 61 CKB in the change cell when sending from a secp256k1 walletBasicFrom one fix

A plain secp256k1_blake160 cell occupies 61 CKB, so when a wallet sends X it must keep at least 61 CKB (the occupied capacity of its own lock) in the change cell, plus the fee, and refuse the send otherwise. The recipient output must also be at least the occupied capacity of the recipient's lock, never less than 61 CKB for a plain address. Enforce the change floor in the transaction builder, and use extra headroom (this runner uses threshold >= amount + 100) for automatic sweeps so fee and change always fit.

#Capacity and cell size #Transaction building and fees · Sources (1) · 2026-10-21

Building a remote CCC signer by extending SignerCkbPublicKeyWorkingFrom one fix

To expose a remote secp256k1 key as a CCC signer, extend ccc.SignerCkbPublicKey(client, publicKey) and override signOnlyTransaction and signMessageRaw to call the backend. The address and lock come from the public key, and signMessageRaw must sign in the "Nervos Message:" format so signMessage and verifyMessage keep working. SignerCkbPublicKey also reports anyone-can-pay addresses of the key, whose cells a backend that only signs the secp256k1 lock cannot spend, so override getAddressObjs to return only the lock you can sign (ckb-keyway had to do this later).

#Witnesses and signatures · Sources (1) · 2026-10-12

Creation witness for an output type script goes in WitnessArgs.output_typeWorkingFrom one fix

A type script that checks a newly created output can read its proof from WitnessArgs.output_type, but the script decides which witness to read: tactus-o1's state proof script loads absolute witness 0 (Source::Input, index 0), not a witness matched to the output index. If that witness is also the first witness of the secp lock group, put the proof in its output_type field next to the 65 byte lock placeholder, and it is covered by the lock signature because the sighash keeps the other WitnessArgs fields and zeroes only the lock.

#Witnesses and signatures · Sources (1) · 2026-10-10

Matching a Script code_hash to its code Cell by hash_typeWorkingSeen again

To check that a Script points at a given deployed code Cell, compare its code_hash with ckb blake2b256 of the Cell's output data when hash_type is data, data1 or data2 (0, 2, 4), and with the hash of that Cell's Type Script when hash_type is type (1). A type selection needs the code Cell to actually carry a Type Script, and other hash_type values are rejected.

#Cell deps and script lookup #Data encoding (molecule, hex, bigints) · Sources (2) · 2026-10-09

Wait for the indexer to reach the block before truncating the devnet chain in reorg testsWorkingFrom one fix

In a devnet reorg test, the inclusion status a client reads from the node does not mean your own indexing service has processed that block. Before truncating the chain below block n, poll that service's indexed block number until it reaches n. Otherwise it never sees the block, never records a rollback, and the test times out on slow CI runners.

#Testing and devnet #Indexer queries and cell collection · Sources (1) · 2026-10-08

EVM owners may hold Omnilock lock args with auth flag 0x12, not only 0x01WorkingFrom one fix

When mapping an Ethereum address to the CKB lock scripts it controls, match Omnilock args 0x12 || addr20 || 0x00 (Ethereum displaying, used by CCC's EVM signer for new addresses) as well as 0x01 || addr20 || 0x00 and PW Lock args = addr20. Otherwise deposits held by CCC created EVM addresses are not recognised. The commit notes this is still pending confirmation in a wallet proof of concept.

#Witnesses and signatures #Login and authorization · Sources (1) · 2026-10-08

Reserve co-signer witness space before completeFeeBy in multi-signer CCC transactionsWorkingReproduced

When a CCC transaction has inputs locked by several secp256k1 signers but the fee is paid by one, call tx.prepareSighashAllWitness(coSignerLock, 65, client) for each co-signer before tx.completeFeeBy(payer, feeRate). Otherwise the fee is estimated without their signature witnesses and may come out short. Each co-signer must own at least one input to have a script group to sign.

#Transaction building and fees #Witnesses and signatures · Sources (1) · 2026-10-06

Page 4 of 5

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.