🚀 The ultimate TypeScript template for building CKB app from smart contracts to user interface. Powered by offckb, ckb-js-vm and CCC.
An all-in-one boilerplate for developing smart contracts app on the CKB blockchain using TypeScript. Write, test, deploy and interact with contracts using familiar JavaScript tooling.
CKB is unique - it allows smart contracts in any language that compiles to RISC-V. The ckb-js-vm is a JavaScript runtime (based on QuickJS) compiled to RISC-V, enabling you to write contracts in TypeScript instead of low-level languages.
- 📝 TypeScript Support - Full type checking and IDE support
- 🧪 Built-in Testing - Full test flow from Jest + ckb-testtool for mock testing to CCC + offckb for local node and testnet testing
- 🚀 One-Command Deploy - Deploy to devnet, testnet, or mainnet
- 🔄 Upgradable Contracts - Type ID pattern support for contract updates
- 🌐 Next.js Frontend - Ready-to-use dApp with CCC wallet integration
- 🤖 AI-Friendly - Documentation optimized for LLM assistants
# Clone the template
git clone https://github.com/cryptape/ckb-script-app my-ckb-project
cd my-ckb-project
# Install dependencies
pnpm install
# Build contracts
pnpm run build
# Run tests
pnpm test# Start frontend (optional)cd app && pnpm devckb-script-app/
├── contracts/ # 📜 Smart contract source code
│ └── hello-world/
│ └── src/
│ └── index.ts # Contract entry point
├── tests/ # 🧪 Contract tests
│ ├── *.mock.test.ts # Mock tests (no node required)
│ └── *.devnet.test.ts # Integration tests
├── dist/ # 📦 Compiled output
│ └── *.bc # Bytecode for CKB
├── deployment/ # 🚀 Deployment artifacts
│ └── scripts.json # Deployed contract info
├── app/ # 🌐 Next.js frontend
│ ├── components/ # React components
│ └── utils/ # CKB utilities
├── .skills/ # 🤖 AI skill patterns
│ ├── ckb-contract-patterns/ # Contract patterns
│ └── ckb-ccc-frontend/ # Frontend patterns
├── scripts/ # 🔧 Build tooling
├── CLAUDE.md # 🤖 AI assistant guide
├── AGENTS.md # 🤖 AI assistant guide
import*asbindingsfrom'@ckb-js-std/bindings';import{log}from'@ckb-js-std/core';functionmain(): number{log.setLevel(log.LogLevel.Debug);// Load current script infoconstscript=bindings.loadScript();log.debug(`Script: ${JSON.stringify(script)}`);// Your validation logic here// Return 0 for success, non-zero for failurereturn0;}bindings.exit(main());pnpm run add-contract my-tokenThis creates:
contracts/my-token/src/index.ts- Contract codetests/my-token.mock.test.ts- Mock test file
| Function | Description |
|---|---|
bindings.loadScript() | Get current script info |
bindings.loadCell(index, source) | Load cell at index |
bindings.loadCellData(index, source) | Load cell data field |
bindings.loadInput(index, source) | Load transaction input |
bindings.loadWitness(index, source) | Load witness data |
bindings.exit(code) | Exit with return code |
bindings.SOURCE_INPUT// Input cellsbindings.SOURCE_OUTPUT// Output cellsbindings.SOURCE_GROUP_INPUT// Same-script input cellsbindings.SOURCE_GROUP_OUTPUT// Same-script output cellsTest without running a CKB node:
import{Resource,Verifier}from'ckb-testtool';describe('my-contract',()=>{test('should validate correctly',async()=>{constresource=Resource.default();consttx=Transaction.default();// Setup transaction cells...constverifier=Verifier.from(resource,tx);awaitverifier.verifySuccess(true);});});pnpm test# Run all tests
pnpm test -- my-contract # Run specific contract testsFor integration testing with a real node:
offckb node # Start local devnet
pnpm test -- devnet # Run devnet tests# Deploy to local devnet (default)
pnpm run deploy
# Deploy to testnet
pnpm run deploy -- --network testnet
# Deploy to mainnet
pnpm run deploy -- --network mainnet
# Deploy with upgradable Type ID
pnpm run deploy -- --network testnet --type-id
# Deploy with custom key
pnpm run deploy -- --network testnet --privkey 0x...After deployment, deployment/scripts.json contains your contract info:
{
"devnet": {
"hello-world.bc": {
"codeHash": "0x...",
"hashType": "type",
"cellDeps": [...]
}
}
}The app/ directory contains a Next.js app with CCC wallet integration.
importscriptsfrom"@/deployment/scripts.json";importsystemScriptsfrom"@/deployment/system-scripts.json";// Build script for ckb-js-vm contractconstmyScript={codeHash: systemScripts.devnet["ckb_js_vm"].script.codeHash,hashType: systemScripts.devnet["ckb_js_vm"].script.hashType,args: buildScriptArgs(scripts.devnet["hello-world.bc"]),};cd app
pnpm install
pnpm dev| Script | Description |
|---|---|
pnpm run build | Build all contracts |
pnpm run build:contract <name> | Build specific contract |
pnpm run build:debug | Build with debug symbols |
pnpm test | Run all tests |
pnpm run add-contract <name> | Create new contract |
pnpm run deploy | Deploy contracts |
pnpm run clean | Remove build outputs |
pnpm run format | Format code with Prettier |
This template includes documentation for AI coding assistants:
| File | Purpose |
|---|---|
CLAUDE.md | Guide for Claude, ChatGPT, and general LLMs |
AGENTS.md | Quick reference for OpenAI agents |
.skills/ | Structured patterns (Agent Skills format) |
The .skills/ folder contains detailed patterns:
| Skill | Description |
|---|---|
ckb-contract-patterns | Smart contract patterns for ckb-js-vm |
ckb-ccc-frontend | Frontend patterns with CCC wallet integration |
When using AI assistants, share the repo URL and they'll understand the project structure.
| Concept | Description |
|---|---|
| Cell | Data unit on CKB (like enhanced UTXO) |
| Lock Script | Defines who can spend a cell |
| Type Script | Defines cell creation/destruction rules |
| Capacity | CKB tokens; also determines storage size |
| Cell Dep | Reference to code/data cells in transaction |
| Witness | Signature and proof data |
- The Little Book of ckb-js-vm - Comprehensive guide
- CKB JS Quick Start - Official docs
- CCC Documentation - Wallet connector
- CKB RFCs - Protocol specs
- ckb-js-vm GitHub - VM source
- Node.js v20 or later
- pnpm package manager
- offckb (optional, for local devnet):
npm install -g @offckb/cli
MIT
Built with ❤️ for the CKB ecosystem