Start here · Glossary · Test yourself · Feed
#Capacity and cell size ✕
23 lessons found. All lessons
Page 1 of 2Next
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
Every output must hold at least its occupied capacity: (8 for the capacity field + 33 + lock args length, plus 33 + type args length if a type script is present, plus data length) × 10^8 shannons. That is 61 CKB for a plain secp256k1 lock with 20 byte args and 63 CKB for a JoyID lock. A fixed payout or fee output set below the recipient lock's minimum is rejected, so choose a constant at or above the largest minimum among the locks you accept.
#Capacity and cell size #Transaction building and fees · Sources (2) · 2026-11-15
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
Under an always-success lock, a test never checks that the signature covers the witnesses. That matters most when contract data shares a WitnessArgs with the signature, for example in inputType. Move the test cells to a secp256k1 lock, using its code cell and dep group from genesis, and sign with ccc.SignerCkbPrivateKey. The 20-byte lock args need 6 more CKB of capacity than the 14-byte fixture args.
#Witnesses and signatures #Testing and devnet #Capacity and cell size · Sources (1) · 2026-11-14
Set the phase-two input since to an absolute epoch counted from the DEPOSIT header, not the withdrawing block. Round the elapsed epochs up to whole 180-epoch cycles, compare epoch fractions by cross-multiplication, and keep the deposit's epoch index and length. The withdrawable amount is occupied + (capacity − occupied) × AR_withdraw / AR_deposit, where AR is a little-endian u64 read from bytes 8..16 of each header's dao field. WitnessArgs.input_type must hold the deposit header's index in header_deps as an 8-byte little-endian u64.
#Since and time locks #Witnesses and signatures #Capacity and cell size · Sources (1) · 2026-11-13
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
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
When quoting capacity before a wallet is connected, use a placeholder lock shaped like the wallet you expect. A JoyID lock has 22 byte args, 2 bytes more than a secp256k1 lock's 20, so every cell carrying the user's lock needs 2 CKB more occupied capacity. Pass the placeholder (for example args of 22 zero bytes) to the same quote function used after connecting, so the pre-connect total is not lower than what a JoyID user will actually commit.
#Capacity and cell size #Transaction building and fees · Sources (1) · 2026-11-10
When a Cheque lock cell (RFC 0039) is spent on the receiver path, rule 1.b.ii requires the Cheque cell's CKB capacity to go back to the sender's lock. An output paying that CKB to the receiver fails with Cheque error 8 (SenderCapacityNotSame). So the Cheque lock cannot be used to deliver plain CKB to the receiver, and in this project's tests it also blocked an owner placed in the receiver role from reclaiming their own CKB.
#Testing and devnet #Capacity and cell size · Sources (1) · 2026-11-09
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.
#Capacity and cell size #Cell deps and script lookup · Sources (1) · 2026-11-08
When a lock script commits to output 0's exact bytes (capacity included), the capacity must be decided before proving and must equal what the transaction ships. In CCC, tx.completeFeeBy(signer) pays the fee by pulling in the signer's cells and adding a change output, so output 0 keeps its capacity and the fee is then paid from extra inputs, which breaks the binding if the proof assumed inputCapacity minus fee. Instead compute the fee from tx.toBytes().length with the witness already at its final length, build output 0 at inputCapacity minus that fee, and check before sending that the fee recomputed on the real transaction equals the planned one.
#Transaction building and fees #Witnesses and signatures #Capacity and cell size · Sources (1) · 2026-11-04
ckb-testtool's Context::verify_tx runs scripts only, so a test can pass with a transaction the node rejects. Build a Consensus from the bundled mainnet chain spec and run ckb-verification's NonContextualTransactionVerifier, CapacityVerifier and DaoScriptSizeVerifier, plus DaoCalculator::transaction_fee for DAO withdraw balance, and add your own checks for inputs below occupied capacity, a cell spent twice and a malformed since (time-dependent maturity can be skipped). Run these on rejected transactions too, so a rejection test fails only for the script rule it targets, or explicitly names the node rule it overlaps.
#Testing and devnet #Capacity and cell size · Sources (1) · 2026-11-02
Page 1 of 2Next
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.