A JavaScript project for developing smart contracts on the CKB blockchain.
This project uses the CKB JavaScript VM (ckb-js-vm) to write smart contracts in typescript. The contracts are compiled to bytecode and can be deployed to the CKB blockchain.
ckb-script-app/
├── contracts/ # Smart contract source code
│ └── hello-world/
│ └── src/
│ └── index.ts # Contract implementation
├── tests/ # Contract tests
│ └── hello-world.test.ts
├── scripts/ # Build and utility scripts
│ ├── build-all.js
│ ├── build-contract.js
│ └── add-contract.js
├── dist/ # Compiled output (generated)
│ ├── hello-world.js # Bundled JavaScript
│ └── hello-world.bc # Compiled bytecode
├── package.json
├── tsconfig.json # TypeScript configuration
├── tsconfig.base.json # Base TypeScript settings
├── jest.config.cjs # Jest testing configuration
└── README.md
- Node.js (v20 or later)
- pnpm package manager
- Install dependencies:
pnpm install
Build all contracts:
pnpm run buildBuild a specific contract:
pnpm run build:contract hello-worldBuild with debug version:
pnpm run build:debugor for specific contract with debug enabled:
pnpm run build:contract:debug hello-worldRun all tests:
pnpm testRun tests for a specific contract:
pnpm test -- hello-worldCreate a new contract:
pnpm run add-contract my-new-contractThis will:
- Create a new contract directory under
contracts/ - Generate a basic contract template
- Create a corresponding test file
- Edit your contract in
contracts/<contract-name>/src/index.ts - Build the contract:
pnpm run build:contract <contract-name> - Run tests:
pnpm test -- <contract-name>
All contracts are built to the global dist/ directory:
dist/{contract-name}.js- Bundled JavaScript codedist/{contract-name}.bc- Compiled bytecode for CKB execution
Tests use the ckb-testtool framework to simulate CKB blockchain execution. Each test:
- Sets up a mock CKB environment
- Deploys the contract bytecode
- Executes transactions
- Verifies results
build- Build all contractsbuild:contract <name>- Build a specific contractbuild:debug- Build all contracts with debug versionbuild:contract:debug <name>- Build a specific contract with debug versiontest- Run all testsadd-contract <name>- Add a new contractdeploy- Deploy contracts to CKB networkdeploy:debug- Deploy contracts with debug version to CKB networkclean- Remove all build outputsformat- Format code with Prettier
Deploy your contracts to CKB networks using the built-in deploy script:
# Deploy to devnet (default)
pnpm run deploy
# Deploy to testnet
pnpm run deploy -- --network testnet
# Deploy to mainnet
pnpm run deploy -- --network mainnetNote that you can change the run deploy to run deploy:debug to deploy the debug version of your smart contracts.
# Deploy with upgradable type ID
pnpm run deploy -- --network testnet --type-id
# Deploy with custom private key
pnpm run deploy -- --network testnet --privkey 0x...
# Combine multiple options
pnpm run deploy -- --network testnet --type-id --privkey 0x...--network <network>- Target network:devnet,testnet, ormainnet(default:devnet)--privkey <privkey>- Private key for deployment (default: uses offckb's deployer account)--type-id- Enable upgradable type ID for contract updates
After successful deployment, artifacts are saved to the deployment/ directory:
deployment/scripts.json- Contract script informationdeployment/<network>/<contract>/deployment.toml- Deployment configurationdeployment/<network>/<contract>/migrations/- Migration history
@ckb-js-std/bindings- CKB JavaScript VM bindings@ckb-js-std/core- Core CKB JavaScript utilities
ckb-testtool- Testing framework for CKB contractsesbuild- Fast JavaScript bundlerjest- JavaScript testing frameworktypescript- TypeScript compilerts-jest- TypeScript support for Jestprettier- Code formatter
MIT