Skip to content

Commit 2d57b61

Browse files
committed
add ckb skill init version
1 parent 3a54a9c commit 2d57b61

22 files changed

+2890
-1
lines changed

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# macOS
2+
.DS_Store
3+
.AppleDouble
4+
.LSOverride
5+
6+
# Editor
7+
*.swp
8+
*.swo
9+
*~
10+
.vscode/
11+
.idea/
12+
13+
# Node (if testing CCC SDK examples)
14+
node_modules/
15+
npm-debug.log*
16+
17+
# Rust (if testing Script examples)
18+
target/
19+
Cargo.lock
20+
21+
# Environment
22+
.env
23+
.env.local

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 CKB Dev Skills Contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 136 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,136 @@
1-
# ckb-dev-skills
1+
# CKB Development Skill for AI
2+
3+
A comprehensive Vibe coding skill for Nervos CKB development (CKB2023 MIRANA best practices).
4+
5+
## Overview
6+
7+
This skill provides with deep knowledge of the CKB development ecosystem:
8+
9+
- **Cell Model**: Generalized UTXO model — Cells, capacity, Live/Dead state
10+
- **Scripts**: On-chain programs (Lock Script, Type Script) running on CKB-VM (RISC-V)
11+
- **Script Language**: Rust with `ckb-std` (default), C with `ckb-c-stdlib`, JS via `ckb-js-vm`
12+
- **DApp SDK**: CCC (`@ckb-ccc/*`) for transaction building, signing, wallet connection
13+
- **Tokens**: sUDT, xUDT, Spore DOB, RGB++ protocol
14+
- **Testing**: `ckb-testtool` (Rust) + `ckb-debugger` (CLI, GDB)
15+
- **Deployment**: OffCKB (local Devnet), Type ID for upgradable Scripts
16+
- **Security**: Capacity validation, Cell counting, reinitialization prevention
17+
- **Fiber Network**: Payment channels, off-chain payments, cross-chain Lightning interop
18+
19+
## Installation
20+
21+
### Manual Install
22+
23+
```bash
24+
git clone https://github.com/nervosnetwork/ckb-dev-skills
25+
cd ckb-dev-skills
26+
./install.sh
27+
```
28+
29+
### Install to Project
30+
31+
```bash
32+
./install.sh --project
33+
```
34+
35+
## Skill Structure
36+
37+
```
38+
skill/
39+
├── SKILL.md # Main skill definition (required)
40+
├── cell-model.md # Cell Model basics
41+
├── script.md # Script structure & types
42+
├── transaction.md # Transaction structure
43+
├── ckb-vm.md # CKB-VM, cycles, syscalls
44+
├── rust-setup.md # Rust environment setup
45+
├── writing-scripts-rust.md # Writing Scripts in Rust
46+
├── other-languages.md # C, JS, Lua options
47+
├── ccc-sdk.md # CCC SDK for DApp development
48+
├── transaction-patterns.md # Transaction composition patterns
49+
├── token-standards.md # sUDT, xUDT, RGB++
50+
├── testing.md # Testing Scripts
51+
├── debugging.md # Debugging Scripts
52+
├── deployment.md # Deployment & tools
53+
├── ecosystem-scripts.md # System/ecosystem Scripts
54+
├── security.md # Security checklist
55+
├── fiber-network.md # Fiber Network (payment channels)
56+
└── resources.md # Curated reference links
57+
```
58+
59+
## Usage
60+
61+
Once installed, Claude Code will automatically use this skill when you ask about:
62+
63+
- CKB on-chain Script (smart contract) development
64+
- Cell Model and UTXO-style state management
65+
- Transaction building, signing, and sending on CKB
66+
- DApp development with CCC SDK (TypeScript/JavaScript)
67+
- Token creation and management (sUDT, xUDT, Spore DOB, RGB++)
68+
- Wallet integration for CKB
69+
- Testing and debugging CKB Scripts
70+
- Deploying Scripts to Devnet/Testnet/Mainnet
71+
- CKB-VM, cycles, and performance optimization
72+
- Molecule serialization format
73+
- Fiber Network payment channels, invoices, and cross-chain swaps
74+
75+
### Example Prompts
76+
77+
```
78+
"Help me set up a new CKB Script project in Rust"
79+
"Create a Lock Script that requires 2-of-3 multisig"
80+
"Build a transaction that transfers CKB using CCC SDK"
81+
"Write tests for my Type Script using ckb-testtool"
82+
"How do I deploy a Script to CKB Testnet?"
83+
"Create a simple UDT token with mint and transfer"
84+
"Debug my Script — it's returning error code 5"
85+
"What's the minimum capacity for a Cell with 32 bytes of data?"
86+
"Help me integrate CKB wallet connection in my React app"
87+
"Review this Script for security issues"
88+
"How do I run a Fiber node and open a payment channel?"
89+
"Send a payment over Fiber Network using invoices"
90+
"Set up a two-node Fiber testnet for local development"
91+
```
92+
93+
## Stack Decisions
94+
95+
This skill encodes opinionated best practices:
96+
97+
| Layer | Default Choice | Alternative |
98+
|-------|---------------|-------------|
99+
| Script Language | Rust + `ckb-std` | C (`ckb-c-stdlib`), JS (`ckb-js-vm`) |
100+
| DApp SDK | CCC (`@ckb-ccc/shell`) | CCC React (`@ckb-ccc/connector-react`) |
101+
| Project Scaffolding | `ckb-script-templates` | Manual setup |
102+
| Unit Testing | `ckb-testtool` | `ckb-debugger` CLI |
103+
| Debugging | `ckb-debugger` + GDB | Debug print via `ckb_debug!` |
104+
| Local Development | OffCKB | Manual CKB node |
105+
| Deployment | Type ID (upgradable) | Direct data deployment |
106+
| Serialization | Molecule ||
107+
| Payment Channels | Fiber Network (fnn) ||
108+
109+
## Content Sources
110+
111+
This skill incorporates best practices from:
112+
113+
- [Nervos CKB Documentation](https://docs.nervos.org/) — Official documentation
114+
- [CCC SDK](https://github.com/ckb-devrel/ccc) — Primary JS/TS SDK
115+
- [ckb-std](https://github.com/nervosnetwork/ckb-std) — Rust standard library for Scripts
116+
- [CKB RFCs](https://github.com/nervosnetwork/rfcs) — Protocol specifications
117+
- [CKB Academy](https://academy.ckb.dev/) — Learning platform
118+
- [Fiber Network](https://github.com/nervosnetwork/fiber) — Payment channel network
119+
- [Fiber Docs](https://docs.fiber.world) — Fiber Network documentation
120+
121+
## Progressive Disclosure
122+
123+
The skill uses Claude Code's progressive disclosure pattern. The main `SKILL.md` provides core guidance and operating procedures. Claude reads the specialized markdown files only when needed for specific tasks, keeping context usage efficient.
124+
125+
## Contributing
126+
127+
Contributions are welcome! Please ensure any updates reflect current CKB ecosystem best practices.
128+
129+
1. Fork the repository
130+
2. Create a feature branch
131+
3. Make your changes
132+
4. Submit a pull request
133+
134+
## License
135+
136+
MIT License

install.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/bash
2+
3+
# CKB Dev Skill Installer for Vibe Coding
4+
# Usage: ./install.sh [--project | --path <path>]
5+
6+
set -e
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
SKILL_NAME="ckb-dev"
10+
SOURCE_DIR="$SCRIPT_DIR/skill"
11+
12+
# Default to personal installation
13+
INSTALL_PATH="$HOME/.claude/skills/$SKILL_NAME"
14+
15+
# Parse arguments
16+
while [[ $# -gt 0 ]]; do
17+
case $1 in
18+
--project)
19+
INSTALL_PATH=".claude/skills/$SKILL_NAME"
20+
shift
21+
;;
22+
--path)
23+
INSTALL_PATH="$2"
24+
shift 2
25+
;;
26+
-h|--help)
27+
echo "CKB Dev Skill Installer"
28+
echo ""
29+
echo "Usage: ./install.sh [OPTIONS]"
30+
echo ""
31+
echo "Options:"
32+
echo " --project Install to current project (.claude/skills/$SKILL_NAME)"
33+
echo " --path PATH Install to custom path"
34+
echo " -h, --help Show this help message"
35+
echo ""
36+
echo "Default: Install to ~/.claude/skills/$SKILL_NAME"
37+
exit 0
38+
;;
39+
*)
40+
echo "Unknown option: $1"
41+
echo "Use --help for usage information"
42+
exit 1
43+
;;
44+
esac
45+
done
46+
47+
# Check if source directory exists
48+
if [ ! -d "$SOURCE_DIR" ]; then
49+
echo "Error: Source directory '$SOURCE_DIR' not found"
50+
exit 1
51+
fi
52+
53+
# Check if SKILL.md exists
54+
if [ ! -f "$SOURCE_DIR/SKILL.md" ]; then
55+
echo "Error: SKILL.md not found in '$SOURCE_DIR'"
56+
exit 1
57+
fi
58+
59+
# Create parent directory if needed
60+
mkdir -p "$(dirname "$INSTALL_PATH")"
61+
62+
# Check if destination already exists
63+
if [ -d "$INSTALL_PATH" ]; then
64+
echo "Warning: '$INSTALL_PATH' already exists"
65+
read -p "Overwrite? (y/N) " -n 1 -r
66+
echo
67+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
68+
echo "Installation cancelled"
69+
exit 0
70+
fi
71+
rm -rf "$INSTALL_PATH"
72+
fi
73+
74+
# Copy skill files
75+
echo "Installing CKB Dev Skill..."
76+
cp -r "$SOURCE_DIR" "$INSTALL_PATH"
77+
78+
echo ""
79+
echo "Successfully installed to: $INSTALL_PATH"
80+
echo ""
81+
echo "Installed files:"
82+
find "$INSTALL_PATH" -type f -name "*.md" | sort | while read -r file; do
83+
echo " - $(basename "$file")"
84+
done
85+
echo ""
86+
echo "The skill is now available in Claude Code."
87+
echo "Try asking about CKB development to activate it!"

skill/SKILL.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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

Comments
 (0)