CKB Pulse
Lessons

What CKB learned

Start here · Glossary · Test yourself · Feed

“Transaction building and fees”

52 lessons found. All lessons

Page 1 of 5

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

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

send_transaction error -1111 (PoolRejectedRBF) is a conflict, not "already in pool"WorkingChecked by the owner

CKB's send_transaction returns -1107 when the same tx is already in the pool, but -1111 (PoolRejectedRBF) when a different pool tx spends one of its inputs and this tx cannot replace it. Treating -1111 like -1107 makes a client resend a tx whose input is gone and only notice the failure much later. Fiber now reports it as a conflict (failing a funding tx at once) while closing txs keep the old handling.

#Network and RPC reliability #Transaction building and fees · Sources (2) · 2026-11-18

CCC client cache can keep dropped transactions; check status without cacheWorkingFrom one fix

A ccc client records the transactions it sends in its cache, so a claim or sweep the chain dropped or rejected stays there with its outputs usable and its inputs spent, which breaks later sends. Check such transactions with client.getTransactionNoCache and treat an undefined result or status "rejected" as dropped. Rebuild that client's cache from the chain before building new sends, and give automated sends their own ccc client so this rebuild does not touch the account's other pending transactions.

Related to the cache clearing and getTransactionNoCache lessons, but adds a distinct remedy: treat undefined or rejected as dropped, and use a separate client for automated sends to isolate its cache.

#Network and RPC reliability #Transaction building and fees · Sources (1) · 2026-11-17

Sign a prepared transaction without broadcasting via CCC signOnlyTransactionWorkingFrom one fix

signer.signOnlyTransaction(tx) asks the CCC signer to sign a transaction you already completed (inputs, fee, cell deps, zero placeholder witness) without preparing or sending it. Treat the wallet as untrusted: pass it a copy, recheck the connected account after it returns, and verify the signed result against the sign hash you got from tx.getSignHashInfo(lock, client) on the prepared transaction (same tx hash, other witnesses untouched, signature recovers to the expected public key).

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

Classifying sendTransaction failures before dropping a pending CKB transactionWorkingFrom one fix

A failed or timed out ccc client.sendTransaction, or a getTransaction status of "rejected" or "unknown", does not prove the transaction can never commit: a node may have taken it, and "rejected" also covers pool removals such as expiry or a full pool. Store the signed bytes before sending. Drop the pending state only on final refusals (ErrorClientVerification, ErrorClientMaxFeeRateExceeded, TransactionFailedToVerify, PoolRejectedMalformedTransaction), or when an input is not live, the transaction that created that input is committed, and the node no longer holds your transaction as pending, proposed or committed. A not-live input alone is not proof, because CCC's getCellLive also returns not live for a cell the node has not seen. Otherwise resend the stored bytes, treating ErrorClientDuplicatedTransaction and PoolRejectedDuplicatedTransaction as success.

#Network and RPC reliability #Transaction building and fees · Sources (1) · 2026-11-08

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

completeFeeBy adds change instead of shrinking outputs, breaking output bound proofsWorkingFrom one fix

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

Reconcile a lost send_transaction response by pinned hash, not by rebuildingWorkingFrom one fix

When a send_transaction response is lost (the node may already have accepted the transaction), this commit pins the signed transaction hash and its input outpoints, and recovers by querying get_transaction for that exact hash and get_live_cell for each input instead of building a new payment. Only a 'committed' status ends the intent; rejected, unknown or spent inputs stay 'uncertain' for operator review, because a fresh rebuild from refreshed cells was shown to let a second payment to the same recipient commit.

#Network and RPC reliability #Transaction building and fees #Indexer queries and cell collection · Sources (1) · 2026-11-02

Dry run a transaction with test_tx_pool_accept before send_transactionWorkingFrom one fix

The CKB node RPC test_tx_pool_accept takes the same params as send_transaction (the snake_case tx JSON without its hash, plus an outputs validator such as "passthrough"). It returns the cycles and fee the pool would accept without broadcasting, so a tool can check a pasted transaction before sending it for real.

#Transaction building and fees #Network and RPC reliability · Sources (1) · 2026-10-30

JoyID signer prices fees with a 1,000 byte signature placeholderWorkingFrom one fix

With CCC and @ckb-ccc/joy-id, prepareTransaction fills the JoyID witness lock with a 1,000 byte placeholder before the fee is computed as ceil((serialized size + 4) x rate / 1000). The real signature is usually shorter (347 bytes in one testnet order), so the committed transaction is smaller and its measured rate is higher than the rate it was built at (7,278 against 5,000 shannons/KB). To recover the build rate, clone the transaction, set the JoyID witness lock back to 1,000 zero bytes, and compute the rate on that size, confirming with tx.estimateFee(rate) equal to the paid fee.

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

Clamp the node's get_fee_rate_statistics median before using it as a fee rateWorkingFrom one fix

Do not pass the node's get_fee_rate_statistics median straight to a transaction builder: a high or untrusted endpoint can set the fee rate for every transaction you build. Clamp it between the minimum relay rate (1,000 shannons/KB) and an app-chosen ceiling, and fall back to the minimum if the call fails, accepting that a ceiling below the real market rate can make confirmation slow. openswap used 1,000 to 5,000 shannons/KB (testnet nodes suggested 33,000 to 47,000) plus a 0.01 CKB per-transaction cap.

#Transaction building and fees #Network and RPC reliability · Sources (1) · 2026-10-29

Page 1 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.