Start here · Glossary · Test yourself · Feed
toastmanAu/openswap ✕
Lessons from toastmanAu/openswap
github.com/toastmanAu/openswap
Do you maintain this project? Confirm its lessons in one issue
14 lessons found. All lessons
Page 1 of 2Next
On-chain since checks use the median time of past blocks, but clients often use the tip header's timestamp, and the two can diverge widely after devnet time travel. Compute deadlines from max(ceil(tipMs/1000), medianSeconds) so minimum-term checks hold on both sides.
#Since and time locks #Testing and devnet · Sources (3) · 2026-11-15
After get_transaction reports tx_status committed, poll get_indexer_tip until its block_number is at least the transaction's block number before calling get_cells. If you query first, the indexer silently returns the pre-transaction cell set with no error.
#Indexer queries and cell collection #Network and RPC reliability · Sources (4) · 2026-11-09
The CKB node's get_transaction RPC does not return a null result for rejected or unknown hashes: it returns an object whose transaction field is null and whose tx_status.status is "rejected" (with tx_status.reason holding the rejection reason) or "unknown". Check res.transaction, not just res, before reading outputs, surface tx_status.reason to users, and make test mocks return this shape rather than result null.
Joined with toastmanAu/openswap@4dbe3232c3.
#Network and RPC reliability #Testing and devnet · Sources (2) · 2026-10-30
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
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
A CCC client caches the outputs of every transaction it sent, so when that transaction loses a race for the same input and never commits, its change cells still look usable to later builds. This campaign calls client.cache.clear() on every client before rebuilding and confirms candidate cells with getCellLiveNoCache rather than trusting cached state.
#Indexer queries and cell collection #Transaction building and fees · Sources (1) · 2026-10-29
For a script referenced by hashType 'data1', put the binary in a cell whose lock is the always fail lock (codeHash 32 zero bytes, hashType data1, args 0x, which no code cell can match) and with no type, so the cell can never be spent and the cell dep stays live; the capacity is locked forever. After sending, read the cell with client.getCellLive(outPoint, true) and assert that ccc.hashCkb(outputData) equals the pinned code hash, that the lock equals the always fail lock and that there is no type, ideally on more than one endpoint. The data1 code hash is already pinned by the binary's content; the immutable lock is what keeps the cell available.
#Cell deps and script lookup #Type ID and upgrades · Sources (1) · 2026-10-29
With CCC client.findTransactionsPaged (scriptSearchMode 'prefix', groupByTransaction: true), each returned transaction has a cells list of {isInput, cellIndex} entries for the cells that matched the searched script. If your logic only needs the matched inputs, fetch parent transactions with getTransaction only for those indexes (plus siblings from a parent you already hold) and skip unrelated inputs such as wallet funding. OpenSwap's market scanner did this together with raising read concurrency to 16, and its first scan went from about 8 to 10 s to about 5.3 s; the gain from this change alone was not measured.
#Indexer queries and cell collection #Network and RPC reliability · Sources (1) · 2026-10-29
A node reporting a transaction you sent as rejected or unknown does not prove it is dead: one node's answer is not proof, and while all its inputs are live the signed bytes could still be rebroadcast by someone and commit. Only release its reserved inputs if a later transaction is guaranteed to conflict with it (here a shared pool cell every later action must spend, so at most one can commit), and also require that every input is still live, that the status is still rejected or unknown when rechecked after the input reads, and that the submission is old enough (2 minutes here), behind an explicit confirmation.
#Transaction building and fees #Network and RPC reliability · Sources (1) · 2026-10-26
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 · Sources (1) · 2026-10-22
A signed CKB transaction that is not committed (not pending, proposed or sent) is still valid and can be broadcast by anyone while all its inputs are live, so do not release its input reservations yet. Release them only after a committed-state live-cell check shows at least one input spent (a spend still in the tx pool does not count), and a second status check confirms the transaction still has not committed. A conflicting spend can still be reorganized away, so require the operator to acknowledge that risk.
#Transaction building and fees #Indexer queries and cell collection #Network and RPC reliability · Sources (2) · 2026-10-22
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 · Sources (1) · 2026-10-09
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.