|
| 1 | +--- |
| 2 | +name: ckb-dev |
| 3 | +description: End-to-end Nervos CKB development playbook. Covers Cell Model, Script (smart contract) development in Rust/C/JS, CCC SDK for DApp building, transaction composition, token standards (sUDT/xUDT/RGB++), Fiber Network (payment channels), testing with ckb-testtool and ckb-debugger, deployment with Type ID, and ecosystem tooling. Targets CKB2023 (MIRANA) best practices. |
| 4 | +user-invocable: true |
| 5 | +--- |
| 6 | + |
| 7 | +# CKB Development Skill |
| 8 | + |
| 9 | +## What this Skill is for |
| 10 | +Use this Skill when the user asks for: |
| 11 | +- CKB on-chain Script (smart contract) development |
| 12 | +- Cell Model and UTXO-style state management |
| 13 | +- Transaction building, signing, and sending on CKB |
| 14 | +- DApp development with CCC SDK (TypeScript/JavaScript) |
| 15 | +- Token creation and management (sUDT, xUDT, Spore DOB, RGB++) |
| 16 | +- Wallet integration for CKB (Omnilock, JoyID, multi-wallet support) |
| 17 | +- Testing and debugging CKB Scripts |
| 18 | +- Deploying Scripts to Devnet/Testnet/Mainnet |
| 19 | +- CKB-VM (RISC-V), cycles, and performance optimization |
| 20 | +- Toolchain setup, version issues, build errors |
| 21 | +- Molecule serialization format |
| 22 | +- Running CKB nodes and RPC interaction |
| 23 | +- Fiber Network (payment channels, invoices, multi-hop payments, cross-chain swaps) |
| 24 | + |
| 25 | +## Default stack decisions (opinionated) |
| 26 | + |
| 27 | +1) **Script language: Rust first** |
| 28 | +- Prefer Rust with `ckb-std` for all new on-chain Scripts. |
| 29 | +- Use C with `ckb-c-stdlib` only for extremely size/cycle-sensitive Scripts. |
| 30 | +- Use JavaScript (ckb-js-vm) for prototyping or educational demos. |
| 31 | + |
| 32 | +2) **DApp SDK: CCC first** |
| 33 | +- Use `@ckb-ccc/shell` for Node.js backends. |
| 34 | +- Use `@ckb-ccc/connector-react` for React frontends with wallet connection. |
| 35 | +- Use `@ckb-ccc/ccc` for custom UI without built-in connector. |
| 36 | + |
| 37 | +3) **Script project scaffolding** |
| 38 | +- Use `cargo generate gh:cryptape/ckb-script-templates workspace` for new projects. |
| 39 | +- Use `make generate CRATE=<name>` to add contracts within a project. |
| 40 | + |
| 41 | +4) **Testing** |
| 42 | +- Default: `ckb-testtool` for Rust unit tests (simulates full CKB environment). |
| 43 | +- Use `ckb-debugger` for command-line execution, cycle profiling, and GDB debugging. |
| 44 | +- Use `ckb-debugger --mode gdb` when you need step-through debugging. |
| 45 | + |
| 46 | +5) **Deployment** |
| 47 | +- Use OffCKB for local Devnet development. |
| 48 | +- Use Type ID pattern for upgradable Scripts. |
| 49 | +- Use `data2` hash_type for new Scripts (targets latest VM version). |
| 50 | + |
| 51 | +6) **Serialization** |
| 52 | +- CKB uses Molecule (not Protobuf/JSON) for on-chain data serialization. |
| 53 | +- Use `@ckb-ccc/ccc` codecs for TypeScript, `molecule` crate for Rust. |
| 54 | + |
| 55 | +## Operating procedure (how to execute tasks) |
| 56 | +When solving a CKB task: |
| 57 | + |
| 58 | +### 1. Classify the task layer |
| 59 | +- Core concepts (Cell Model, Script, Transaction structure) |
| 60 | +- On-chain Script development (Rust/C/JS) |
| 61 | +- DApp / client-side development (CCC SDK, wallet) |
| 62 | +- Payment channels and off-chain payments (Fiber Network) |
| 63 | +- Testing and debugging |
| 64 | +- Deployment and infrastructure |
| 65 | + |
| 66 | +### 2. Pick the right building blocks |
| 67 | +- Script development: Rust + ckb-std + ckb-script-templates |
| 68 | +- DApp client: CCC SDK (@ckb-ccc/shell or @ckb-ccc/connector-react) |
| 69 | +- Testing: ckb-testtool (Rust) + ckb-debugger (CLI) |
| 70 | +- Local dev: OffCKB |
| 71 | +- Payment channels: Fiber Network (fnn node + JSON-RPC) |
| 72 | + |
| 73 | +### 3. Implement with CKB-specific correctness |
| 74 | +Always be explicit about: |
| 75 | +- Cell capacity requirements (minimum 61 CKBytes, recommend 62+) |
| 76 | +- Lock Script vs Type Script distinction and execution rules |
| 77 | +- `cell_deps` inclusion for referenced Script code |
| 78 | +- `outputs_data` array matching `outputs` array length |
| 79 | +- hash_type selection (`data2` for new, `type` for upgradable via Type ID) |
| 80 | +- Transaction fee = sum(input capacities) - sum(output capacities) |
| 81 | + |
| 82 | +### 4. Add tests |
| 83 | +- Script tests: ckb-testtool with both success and failure cases. |
| 84 | +- Transaction tests: verify cycle consumption is reasonable. |
| 85 | +- Use `context.dump_tx()` to generate ckb-debugger transaction files. |
| 86 | + |
| 87 | +### 5. Deliverables expectations |
| 88 | +When you implement changes, provide: |
| 89 | +- Exact files changed |
| 90 | +- Commands to build (`make build`) and test (`make test`) |
| 91 | +- Cycle consumption estimates where relevant |
| 92 | +- Risk notes for anything touching signatures, token transfers, or capacity management |
| 93 | + |
| 94 | +## Progressive disclosure (read when needed) |
| 95 | +- Cell Model basics: [cell-model.md](cell-model.md) |
| 96 | +- Script structure & types: [script.md](script.md) |
| 97 | +- Transaction structure: [transaction.md](transaction.md) |
| 98 | +- CKB-VM, cycles, syscalls: [ckb-vm.md](ckb-vm.md) |
| 99 | +- Rust environment setup: [rust-setup.md](rust-setup.md) |
| 100 | +- Writing Scripts in Rust: [writing-scripts-rust.md](writing-scripts-rust.md) |
| 101 | +- Other Script languages (C, JS, Lua): [other-languages.md](other-languages.md) |
| 102 | +- CCC SDK (DApp development): [ccc-sdk.md](ccc-sdk.md) |
| 103 | +- Transaction composition patterns: [transaction-patterns.md](transaction-patterns.md) |
| 104 | +- Token standards (sUDT, xUDT, RGB++): [token-standards.md](token-standards.md) |
| 105 | +- Testing Scripts: [testing.md](testing.md) |
| 106 | +- Debugging Scripts: [debugging.md](debugging.md) |
| 107 | +- Deployment & tools: [deployment.md](deployment.md) |
| 108 | +- Ecosystem Scripts: [ecosystem-scripts.md](ecosystem-scripts.md) |
| 109 | +- Security checklist: [security.md](security.md) |
| 110 | +- Fiber Network (payment channels): [fiber-network.md](fiber-network.md) |
| 111 | +- Curated resources: [resources.md](resources.md) |
0 commit comments