Skip to content

zk-steve/offckb

Repository files navigation

OffCKB

npm CI npm npm node

CKB local development network for your first try.

  • One-line command to start a devnet
  • no docker required
  • pre-funded test accounts
  • packed with the most useful scripts like Omnilock and Spore-contract
  • multiple minimal Dapp templates to learn and get your hands dirty

Start building on Nervos blockchain, right now, right away!

Table of Contents

Install

npm install -g @offckb/cli

Usage

offckb node # start the devnet of CKB, `ctrl-c` to stop running the chain
offckb clean # clean the devnet data, needs to stop running the chain first

offckb init <project-name> # init a CKB Dapp typescript boilerplate from multiple templates

offckb accounts # list 20 accounts info with prefund CKB tokens
offckb list-hashes # list built-in scripts hashes, equals `ckb list-hashes`

Get started

Step 1: Create A Project

offckb init my-awesome-ckb-dapp

## select the template for your boilerplate
? Select a dapp template (Use arrow keys)
❯ Transfer CKB
  Issue Coin With XUDT scripts
a simple dapp to check CKB balance and transfer CKB from address to address
init CKB dapp project: /Users/ckb/Desktop/offckb/my-awesome-ckb-dapp
✨  Done in 7.52s.

## start running
cd my-awesome-ckb-dapp
yarn && yarn start

## results
yarn run v1.22.19
$ parcel index.html
Server running at http://localhost:1234
✨ Built in 10ms

Step 2: Start the Devnet

Open another terminal and run:

offckb node

# result
# ...
CKB-Miner: 2024-03-04 14:35:12.563 +00:00 client INFO ckb_miner::miner  Found! #3181 0x3749481a320824fe21077eaa8ec9d024a7b62d031720c27c1ef1681e8ab349e8

CKB-Miner: 2024-03-04 14:35:17.567 +00:00 client INFO ckb_miner::miner  Found! #3184 0xa612a9ea35f292a6473e23e88856283aea8b1bc6a607147bef5c06c94e964f2f
#...

You can leave this terminal open to keep the devnet running, feel free to ctrl+c to exit the terminal and stop the local blockchain.

Step 3: Access Pre-funded Accounts

Open another terminal and check the accounts to use:

offckb accounts

# result
Print account list, each account is funded with 42_000_000_00000000 capacity in the genesis block.
[
  {
    privkey: '0x6109170b275a09ad54877b82f7d9930f88cab5717d484fb4741ae9d1dd078cd6',
    pubkey: '0x02025fa7b61b2365aa459807b84df065f1949d58c0ae590ff22dd2595157bffefa',
    lockScript: {
      codeHash: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8',
      hashType: 'type',
      args: '0x8e42b1999f265a0078503c4acec4d5e134534297'
    },
    address: 'ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqvwg2cen8extgq8s5puft8vf40px3f599cytcyd8',
    args: '0x8e42b1999f265a0078503c4acec4d5e134534297'
  },
  {
    privkey: '0x9f315d5a9618a39fdc487c7a67a8581d40b045bd7a42d83648ca80ef3b2cb4a1',
    pubkey: '0x026efa0579f09cc7c1129b78544f70098c90b2ab155c10746316f945829c034a2d',
    lockScript: {

Copy some private keys and visit http://localhost:1234 to play your first CKB Dapp!

Dapp Templates

offckb packs some basic minimal Dapp templates for you to learn and get started with. By running offckb init, you can select the different Dapp templates to quickly set up a local Dapp project targeting the local blockchain with built-in scripts and accounts.

The Dapp templates often involve interaction with some most useful smart contracts on CKB like xUDT/Spore/Omnilock. The best thing is those Dapp examples also come with detailed tutorial documents from docs.nervos.org. The source codes of these templates are also maintained here.

View and transfer balance

A simple Dapp to check CKB balance and transfer CKB.

Tutorial

Write & read on-chain messages

A simple Dapp to issue your own token via XUDT scripts.

Tutorial

Issue custom token via xUDT scripts

A simple Dapp to store & retrieve data from a Cell.

Tutorial

Create on-chain digital object via Spore protocol

A simple Dapp to create on-chain digital objects with spore scripts.

Tutorial

Built-in scripts

Accounts

offckb comes with 20 accounts, each account is funded with 42_000_000_00000000 capacity in the genesis block.

all the private keys are recorded in the account/keys file. detail informations about each account are recorded in the account/account.json file.

⚠️ DO NOT SEND REAL ASSETS INTO ALL THESE ACCOUNTS, YOU CAN LOOSE YOUR MONEY ⚠️

About Lumos

offckb uses Lumos as the CKB Dapp framework to build the template projects.

Contributing

check development doc

About

CKB local development network for your first try.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 76.1%
  • Makefile 9.5%
  • Rust 7.0%
  • JavaScript 5.8%
  • Shell 1.2%
  • CSS 0.4%