CKB Pulse
经验

CKB 学到了什么

从这里开始 · 术语表 · 自测 · 订阅

经验用英文撰写,请用英文搜索。

“Transaction building and fees”

找到 52 条经验。 全部经验

第 4 页,共 5 页

JoyID lock witness outputType may carry a subkey proof, so type script data must move elsewhere实践来自一次修复

When the funding wallet uses the JoyID lock, its WitnessArgs outputType may carry a subkey unlock proof, so do not put your own type script data in that witness's outputType. Place the type script action in another witness index and align the related output index with it. Size the fee estimate's signature placeholder for JoyID's larger witness (openswap uses 1000 bytes) instead of the 65 byte secp256k1 size.

#Witnesses and signatures #Transaction building and fees · 来源(1) · 2026-10-22

Keep at least 61 CKB in the change cell when sending from a secp256k1 wallet基础来自一次修复

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 · 来源(1) · 2026-10-21

Carry type script and data into the output when spending a lock-only custody cell实践来自一次修复

When a custom lock's spend rebuilds an output from an input cell that may carry a type script (a UDT held in custody, say), copy cell.cellOutput.type and cell.outputData into the output and change only the lock; writing outputsData "0x" with no type burns or strands the token. Add the type script's cell deps to the transaction before signing, because the signature covers the cell deps and callers cannot append them afterwards, and refuse to build the spend if a typed cell comes without them. If the lock also constrains who gets the capacity (as Tranfr's recipient claim does today), follow that rule instead of a plain copy.

#Transaction building and fees #Cell deps and script lookup #Witnesses and signatures · 来源(1) · 2026-10-21

Plain CKB transfer with a CCC signer基础来自一次修复

With CCC, a simple CKB transfer is built as ccc.Transaction.from({ outputs: [{ lock, capacity }] }), then transaction.completeInputsByCapacity(signer) and transaction.completeFeeBy(signer) are called before signer.sendTransaction(transaction). The recipient lock comes from ccc.Address.fromString(address, signer.client), and its .script is used as the output lock.

#Transaction building and fees #Witnesses and signatures · 来源(1) · 2026-10-12

Type Script group membership and group witness index derived from the full script hash实践来自一次修复

When locating a Type Script group off chain, match input and output cells by the blake2b hash of the complete Script (code_hash, hash_type, args), never by code hash alone. By convention (RFC 22 for lock groups), a group's witness sits at the transaction index of its first input, or of its first output if the group has no inputs. CKB does not enforce this: the script picks which witness it reads, and which WitnessArgs field (input_type or output_type) holds the data is the protocol's own choice.

#Witnesses and signatures #Transaction building and fees · 来源(1) · 2026-10-09

Secp256k1 sighash lock groups cover non contiguous later group witnesses实践来自一次修复

With the bundled secp256k1 blake160 sighash lock, all inputs sharing the same lock form one group even when another owner's inputs sit between them. The signature goes in the witness at the group's first input index, and changing a later group witness (which leaves the tx hash unchanged) still fails verification at Inputs[first].Lock. So composed multi owner transactions must place one signature placeholder per lock group at its first input and finalize every group witness before signing.

#Witnesses and signatures #Transaction building and fees · 来源(1) · 2026-10-09

Full-balance UDT burn is valid for SUDT and plain xUDT实践来自一次修复

Burning a UDT's entire balance is accepted by SUDT and xUDT without extensions, because those scripts allow output amount to be less than or equal to input amount. offckb removed a guard that rejected destroyAmount === totalBalance and now still emits a zero-balance type cell (16-byte zero amount), which is valid. Extension-enabled xUDT was not covered by this change.

#Transaction building and fees #Capacity and cell size · 来源(1) · 2026-10-08

Output type scripts need cell deps too, including the native DAO type基础来自一次修复

CKB runs the type script of every output (not only input locks and input types), so a transaction that creates a native DAO deposit must include the DAO type's code cell (genesis tx0 index 2) as a cell dep, or the node rejects it with ScriptNotFound on Outputs[i].Type. Pre-send checks that only verify deps for input locks will miss this; check every input lock, input type and output type, deduplicated by code_hash and hash_type.

#Cell deps and script lookup #Transaction building and fees · 来源(1) · 2026-10-05

Deriving minimum cell capacity with ccc.CellOutput.from and output data实践已复现

In CCC, calling ccc.CellOutput.from({lock, type}, outputData) without a capacity fills capacity with the cell's occupied size, so it serves as the minimum capacity check for change or receipt cells. This commit uses it to reject dust change before and after subtracting the fee (via transaction.estimateFee), and to top up a receipt cell whose received CKB is below its occupied capacity.

#Capacity and cell size #Transaction building and fees · 来源(1) · 2026-10-01

Recompute occupied capacity when a state cell grows in a transition实践来自一次修复

When a transaction replaces a cell with one holding larger data (here 101 to 207 bytes under the same type script), compute the new occupied floor as 8 + data length + lock (32 code hash + 1 hash type + args) + type (32 + 1 + args) bytes in CKB, and top up from another input if the old capacity falls short (312 CKB input vs a 318 CKB floor here). If the type script also requires output capacity >= input capacity, use the larger of the two bounds rather than shrinking to the floor.

adds top up and max(floor, input capacity) rule beyond the occupied capacity formula lesson

#Capacity and cell size #Transaction building and fees · 来源(1) · 2026-09-25

Place a script's raw witness at the index of the input it validates实践来自一次修复

When a type script reads its proof with load_witness(index, Source::Input) for its own input, the builder must put that raw witness at exactly that input's index. This commit puts the ledger cell at input 0 so its proof is witness 0, and pads the remaining witnesses with "0x" so witnesses.length equals inputs.length and a later funding/signing step appends rather than displaces it.

#Witnesses and signatures #Transaction building and fees · 来源(1) · 2026-09-25

Use the secp256k1 sighash dep group, not the bare code cell, as the lock dep实践来自一次修复

When a hand-built transaction spends a secp256k1_blake160_sighash_all cell, it needs a cell dep for that lock. That dep should be the genesis dep group (dep_type dep_group), not the bare code cell in genesis tx0, because the lock also loads the secp256k1_data table from a second cell. With only the code cell, ScriptNotFound goes away but the lock then fails inside execution.

#Cell deps and script lookup #Transaction building and fees · 来源(2) · 2026-09-25

第 4 页,共 5 页

文本采用 CC BY 4.0:请署名 LusoCryptoLabs, CKB lessons,并附上经验的链接。 JSON · 想修改或撤下某条经验?请提交 issue。