CKB Pulse

All lessons · CCC (TypeScript SDK) · Start here · Glossary

Transaction size for fee rate is serialized bytes plus 4WorkingFrom one fix

From one fix · Check: partly right · Checked 2026-11-19

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.

Why it matters: Without the extra 4 bytes, or if witnesses are left out, the computed size and fee rate do not match what the node counts, so the displayed or chosen fee rate is off.

Pattern

Prefer
}).toBytes().length + 4;

Taken from the commit, shortened.

Reproduced by a test

A public test runs what this lesson says on @ckb-ccc/core 1.23.1, with no node. Anyone can run it. It covers a part of the lesson: the size rule as CCC applies it, not the node count nor weight by cycles.

tests/ccc/transaction-size.test.mjs

Concepts
Transaction building and fees, Data encoding (molecule, hex, bigints)
Evidence
From one fix: from one project, checked against its commit
First seen
2026-10-17
Last changed
2026-10-17
Last checked
2026-11-19
Check against the commit
partly right: a true core, with a part that is loose or too wide

Sources (1)

More about CCC (TypeScript SDK)

All 33 in this topic

Do you maintain a project this lesson came from? Confirm or correct it

Cite this lesson
LusoCryptoLabs, "Transaction size for fee rate is serialized bytes plus 4", CKB lessons, https://pulse.lusocryptolabs.com/learned/ccc/transaction-size-for-fee-rate-is-serialized-bytes-plus-4, CC BY 4.0, last changed 2026-10-17.

Drawn from public commits and checked against the commit each one came from and the project's code today. Read the source before you rely on one. Text under CC BY 4.0: credit LusoCryptoLabs, CKB lessons, with a link to the lesson. Want a lesson changed or removed? Open an issue.