- capacity — the amount of CKB shannons it holds (1 CKB = 10⁸ shannons)
- lock script — who can spend it (authorization)
- type script (optional) — what rules it must follow (validation)
- data (optional) — arbitrary bytes
Transaction class in CCC is a builder that lets you describe what you want, then fills in the missing pieces automatically.
Create a transaction
UseTransaction.from to construct a transaction from a plain object. You only need to specify the outputs you want — inputs and fees come later:
ccc.fixedPointFrom(100) converts a human-readable CKB amount into shannons (100n * 10n ** 8n).
You can pass initial inputs, cell deps, or witnesses if you already know them:
Add outputs
After construction, add more outputs withaddOutput:
Complete inputs
Once you know what outputs the transaction must produce, callcompleteInputsByCapacity to collect enough input cells from the signer’s wallet to cover the output capacity:
ErrorTransactionInsufficientCapacity if the wallet does not have enough CKB.
Pay fees
After inputs are complete, callcompleteFeeBy to calculate the required fee, add a change output back to the signer’s address, and collect additional inputs if needed:
Add cell deps
Scripts referenced by a transaction’s inputs or outputs must be listed as cell deps so the CKB VM can load them. UseaddCellDepsOfKnownScripts to look them up by name:
signTransaction / sendTransaction, so you typically only need to add deps for type scripts you introduce yourself.
Full transfer example
The following example is taken directly from the CCC examples package. It sends 100 CKB to the signer’s own recommended address:1
Describe outputs
Call
ccc.Transaction.from with the outputs you want to create.2
Collect inputs
Call
tx.completeInputsByCapacity(signer) to pull in enough cells from the wallet.3
Pay fees
Call
tx.completeFeeBy(signer) to calculate and collect the network fee, and route change back to the signer.4
Send
Call
signer.sendTransaction(tx) to sign and broadcast. It returns the transaction hash.