Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ckb-devrel/ccc/llms.txt

Use this file to discover all available pages before exploring further.

New to CKB? Read the Nervos CKB Docs for foundational knowledge.

What is the cell model?

CKB uses a generalized UTXO model called the cell model. Like Bitcoin UTXOs, cells are discrete units of state that are consumed by transactions and replaced with new cells. Unlike Bitcoin UTXOs, each cell can store arbitrary data and be governed by programmable scripts. Every cell has four fields:
FieldTypeDescription
capacityNumStorage space in Shannon (1 CKB = 100,000,000 Shannon)
lockScriptDefines ownership — who can consume this cell
typeScript | undefinedDefines asset behavior — optional type constraints
outputDataHexArbitrary bytes stored in the cell
In CCC, the CellOutput class represents the structured output portion of a cell:
// From packages/core/src/ckb/transaction.ts
export class CellOutput {
  constructor(
    public capacity: Num,
    public lock: Script,
    public type?: Script,
  ) {}
}
A full on-chain cell (with its location on the chain) is represented by the Cell class:
// From packages/core/src/ckb/transaction.ts
export class Cell extends CellAny {
  constructor(
    public outPoint: OutPoint,
    cellOutput: CellOutput,
    outputData: Hex,
  ) {}
}

Scripts

Scripts are the programmable logic attached to cells. CKB executes scripts in a RISC-V virtual machine to validate transactions.
// From packages/core/src/ckb/script.ts
export class Script {
  constructor(
    public codeHash: Hex,   // Hash identifying the script code
    public hashType: HashType, // "type" | "data" | "data1" | "data2"
    public args: Hex,       // Arguments passed to the script
  ) {}
}
You can create a Script from a plain object:
const script = Script.from({
  codeHash: "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
  hashType: "type",
  args: "0xabcdef...",
});

Lock scripts

A lock script defines ownership of a cell. A transaction can only consume a cell if the lock script’s conditions are satisfied — typically by providing a valid cryptographic signature. The most common lock on CKB is Secp256k1Blake160, which works similarly to Bitcoin’s P2PKH.

Type scripts

A type script constrains how a cell can be transformed. It runs on both the consumed inputs and the created outputs, making it suitable for enforcing asset rules — for example, ensuring a UDT (User-Defined Token) supply is not inflated when tokens are transferred. Type scripts are optional. A cell without a type script has no asset-level constraints beyond its lock.

Capacity and Shannon

Capacity is measured in Shannon — the smallest unit of CKB:
1 CKB = 100,000,000 Shannon
Use ccc.fixedPointFrom() to convert human-readable CKB amounts to Shannon:
import { ccc } from "@ckb-ccc/ccc";

// Convert 10 CKB to Shannon (returns bigint 1_000_000_000n)
const capacity = ccc.fixedPointFrom("10");

// Convert from number
const capacity2 = ccc.fixedPointFrom(10); // 1_000_000_000n

// Capacity is stored as a bigint (Num/FixedPoint)
const capacityBigInt: bigint = ccc.fixedPointFrom("61.5");
The fixedPointFrom function has a default decimal precision of 8, matching CKB’s Shannon denominator.

OutPoint

An OutPoint uniquely identifies a specific cell on the chain by referencing the transaction that created it and its position within that transaction’s outputs:
// From packages/core/src/ckb/transaction.ts
export class OutPoint {
  constructor(
    public txHash: Hex,  // Transaction hash
    public index: Num,   // Output index within that transaction
  ) {}

  static from(outPoint: OutPointLike): OutPoint {
    // Example: OutPoint.from({ txHash: "0x...", index: 0 })
  }
}
When a cell is consumed as a transaction input, it is referenced via its OutPoint through a CellInput:
// From packages/core/src/ckb/transaction.ts
export class CellInput {
  constructor(
    public previousOutput: OutPoint, // Points to the cell being consumed
    public since: Num,               // Time-lock constraint (0 = no constraint)
    public cellOutput?: CellOutput,
    public outputData?: Hex,
  ) {}
}

Addresses

A CKB address is an encoding of a lock script. Addresses are derived from the script’s codeHash, hashType, and args, combined with a network prefix (ckb for mainnet, ckt for testnet).
// From packages/core/src/address/index.ts
export class Address {
  constructor(
    public script: Script,
    public prefix: string,
  ) {}

  // Parse an address string back to its Script
  static async fromString(
    address: string,
    clients: Client | Record<string, Client>,
  ): Promise<Address> {}

  // Construct from a script and client (uses client.addressPrefix)
  static fromScript(script: ScriptLike, client: Client): Address {}

  // Encode back to bech32m string
  toString(): string {}
}
Two addresses using the same lock script are identical. When you call signer.getRecommendedAddress(), CCC encodes the signer’s lock script into the appropriate address format for the connected network.

How CCC abstracts the cell model

CCC provides TypeScript classes and methods that manage the low-level details of the cell model:
  • Transaction.from() — constructs a transaction from a plain object, automatically calculating capacities where omitted
  • completeInputsByCapacity(signer) — finds and adds input cells from the signer’s address to cover required capacity
  • completeFeeBy(signer) — calculates the transaction fee and adds a change output
  • Script.fromKnownScript(client, KnownScript.Secp256k1Blake160, args) — looks up well-known script code hashes by name
You rarely need to construct raw OutPoint or Script objects by hand. CCC’s helper methods handle encoding, hashing, and on-chain lookups for you.

Build docs developers (and LLMs) love