Code Examples

Ready-to-run code examples for CCC — open them in the Playground, clone them for your own projects, or reference them as patterns.

Edit on GitHub

Browse our collection of runnable code examples and interactive tools. Cards tagged playground open directly in the CCC Playground; cards tagged app link to the CCC App — a mini-toolset for CKB that lets you perform common operations through a graphical interface, even if you're not a developer.

Use the tag filter below to narrow down examples by category.

Transfer CKB

Send a specified amount of native CKB to another address. Demonstrates the declare → fill → fee → send pattern.

playgroundtransaction
packages/examples/src/transfer.ts

Transfer All CKB

Sweep an entire wallet's CKB balance into a single output. Uses completeInputsAll and completeFeeChangeToOutput.

playgroundtransaction
packages/examples/src/transferAll.ts

Transfer UDT Token

Transfer xUDT fungible tokens between addresses. Demonstrates UDT cell construction and input completion.

playgroundtransactionudt
packages/examples/src/transferUdt.ts

Sign & Verify Message

Sign an arbitrary message with the connected wallet and verify the signature on-chain. Works across all wallet types.

playgroundwallet
packages/examples/src/sign.ts

Custom UI — Specified Wallet

Connect a specific wallet type in your own custom UI without using the built-in connector modal.

playgroundwallet
packages/examples/src/customUi.ts

Custom UI — All Wallets with Controller

Enumerate and connect all supported wallets using SignersController for a fully custom wallet UI.

playgroundwallet
packages/examples/src/customUiWithController.ts

Query Balance

Query the CKB balance of any address on testnet or mainnet. A simple read-only script.

playgroundquery
packages/examples/src/queryBalance.ts

Query Cells

Iterate over live cells owned by an address. Demonstrates the cell collector pattern.

playgroundquery
packages/examples/src/queryCells.ts

Query Transactions

Fetch transaction history for an address. Shows how to use the transaction iterator.

playgroundquery
packages/examples/src/queryTransactions.ts

NervosDAO Deposit & Withdraw

Deposit CKB into NervosDAO and withdraw with interest. Covers the full DAO lifecycle.

playgroundtransaction
packages/examples/src/dao.ts

Create Spore DOB

Mint an on-chain digital object (DOB) using the Spore protocol. Demonstrates cluster creation and content upload.

playgroundtransactionspore
packages/examples/src/createSpore.ts

Transfer Spore DOB

Transfer an existing Spore DOB to another address.

playgroundtransactionspore
packages/examples/src/transferSpore.ts

Backend Transfer (Node.js)

Send CKB from a Node.js backend using @ckb-ccc/shell with a private key signer — no browser required.

backendtransaction
packages/examples/src/backendTransfer.ts

DOB Cookbook — Colorful Loot

Create a colorful loot DOB using the Spore DOB Cookbook recipes. Demonstrates advanced DOB patterns.

playgroundspore
sporeprotocol/dob-cookbook

Issue xUDT — Single-Use Lock

Issue a new xUDT token using the Single-Use Lock pattern. The lock is consumed after issuance, preventing re-minting.

apptransactionudt
packages/demo/src/app/connected/(tools)/IssueXUdtSus/page.tsx

Issue xUDT — Type ID

Issue an xUDT token controlled by a Type ID cell, allowing future minting by the same controller.

apptransactionudt
packages/demo/src/app/connected/(tools)/IssueXUdtTypeId/page.tsx

Create Spore Cluster

Create a Spore Cluster — a logical grouping for on-chain digital objects (DOBs).

apptransactionspore
packages/demo/src/app/connected/(tools)/CreateSporeCluster/page.tsx

Mint Spore

Mint a Spore DOB under a cluster through the CCC App UI.

apptransactionspore
packages/demo/src/app/connected/(tools)/MintSpore/page.tsx

Transfer / Melt Spore

Transfer a Spore DOB to another address, or melt (destroy) it to reclaim CKB capacity.

apptransactionspore
packages/demo/src/app/connected/(tools)/TransferSpore/page.tsx

Transfer Spore Cluster

Transfer ownership of a Spore Cluster to another address.

apptransactionspore
packages/demo/src/app/connected/(tools)/TransferSporeCluster/page.tsx

Time-Locked Transfer

Send CKB with a time lock — the recipient cannot spend the output until a specified block number or timestamp.

apptransaction
packages/demo/src/app/connected/(tools)/TimeLockedTransfer/page.tsx

SSRI Contract Call

Interact with on-chain smart contracts through the SSRI (Script-Sourced Rich Information) protocol.

apptransaction
packages/demo/src/app/connected/(tools)/SSRI/page.tsx

Transfer CKB (Lumos)

Transfer native CKB using the legacy Lumos SDK with CCC's compatibility patches.

apptransaction
packages/demo/src/app/connected/(tools)/TransferLumos/page.tsx

CKB Hash Calculator

Calculate the CKB hash (Blake2b-256) of any message. A quick utility for developers.

apptool
packages/demo/src/app/utils/(tools)/Hash/page.tsx

Mnemonic & Keypair Generator

Generate BIP-39 mnemonic words and derived keypairs. Optionally encrypt to a keystore file.

apptool
packages/demo/src/app/utils/(tools)/Mnemonic/page.tsx

Keystore Decryptor

Decrypt a CKB keystore file to recover the private key.

apptool
packages/demo/src/app/utils/(tools)/Keystore/page.tsx

Dep Group Manager

View and manage CKB dependency groups (DepGroup) used in transaction cell deps.

apptool
packages/demo/src/app/utils/(tools)/DepGroup/page.tsx

Contribute your examples

We welcome community contributions! Whether it's a handy utility script, an interesting on-chain data analysis, or an integration example for a new protocol — it can be included here to help more people get started with CKB development.

Via GitHub Pull Request

To have your example included in the official repository:

Fork and clone the repo

Go to ckb-devrel/ccc, click Fork, then clone locally:

git clone https://github.com/<your-username>/ccc.git
cd ccc

Write your script

Create a new .ts file in packages/examples/src/, using camelCase naming (e.g. myNewExample.ts). Your script should:

  • Import the SDK from @ckb-ccc/ccc
  • Import render, signer, etc. from @ckb-ccc/playground
  • Call await render(tx) at key steps to enable visualization in the Playground

See transfer.ts for a reference.

Test locally

Paste your script into the Playground and verify it runs correctly on Testnet.

Open a Pull Request

Push to your fork and open a PR against the master branch of ckb-devrel/ccc. Briefly describe the example's purpose and use case in the PR description.

Quick share (no PR needed)

The Playground can load code from any publicly accessible URL via the ?src= parameter — your GitHub repo, a Gist, or any raw file URL:

https://live.ckbccc.com/?src=<your-raw-file-url>

Share the generated link with colleagues or the community — they can open it and run your code immediately.

The built-in Share button stores code on Nostr relay nodes. Nostr share links are great for quick collaboration, but relay nodes do not guarantee permanent data retention — links may expire over time. For long-lived, stable share links, host your script in a GitHub repository and load it via ?src=https://raw.githubusercontent.com/... — the link will remain valid as long as the repository and file exist.

On this page