π 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 * as bindings from '@ckb-js-std/bindings';
import { log } from '@ckb-js-std/core';
function main(): number {
log.setLevel(log.LogLevel.Debug);
// Load current script info
const script = bindings.loadScript();
log.debug(`Script: ${JSON.stringify(script)}`);
// Your validation logic here
// Return 0 for success, non-zero for failure
return 0;
}
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 cells
bindings.SOURCE_OUTPUT // Output cells
bindings.SOURCE_GROUP_INPUT // Same-script input cells
bindings.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 () => {
const resource = Resource.default();
const tx = Transaction.default();
// Setup transaction cells...
const verifier = Verifier.from(resource, tx);
await verifier.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.
import scripts from "@/deployment/scripts.json";
import systemScripts from "@/deployment/system-scripts.json";
// Build script for ckb-js-vm contract
const myScript = {
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