@offckb/cli 0.4.9-canary-2b6b3af.0 → 0.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +77 -23
  2. package/build/index.js +2270 -670
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -18,7 +18,7 @@ CKB local development network for your first try.
18
18
 
19
19
  There are BREAKING CHANGES between v0.3.x and v0.4.x, make sure to read the [migration guide](/docs/migration.md) before upgrading.
20
20
 
21
- ----
21
+ ---
22
22
 
23
23
  - [OffCKB](#offckb)
24
24
  - [Install](#install)
@@ -66,6 +66,7 @@ ckb development network for your first try
66
66
 
67
67
  Options:
68
68
  -V, --version output the version number
69
+ --json Output one command result as JSON on stdout and logs as NDJSON on stderr
69
70
  -h, --help display help for command
70
71
 
71
72
  Commands:
@@ -84,6 +85,9 @@ Commands:
84
85
  debugger Port of the raw CKB Standalone Debugger
85
86
  status [options] Show ckb-tui status interface
86
87
  config <action> [item] [value] do a configuration action
88
+ devnet config Edit devnet configuration
89
+ devnet info Show fork metadata and node/indexer readiness
90
+ devnet fork [options] Fork Mainnet/Testnet state into the local devnet
87
91
  help [command] display help for command
88
92
  ```
89
93
 
@@ -92,7 +96,7 @@ _Use `offckb [command] -h` to learn more about a specific command._
92
96
  ## Get started
93
97
 
94
98
  ### 1. Run a Local CKB Devnet {#running-ckb}
95
-
99
+
96
100
  Start a local blockchain with one command:
97
101
 
98
102
  ```sh
@@ -141,17 +145,17 @@ offckb node stop
141
145
 
142
146
  **Agent-Friendly JSON Output**
143
147
 
144
- For programmatic consumption or agent integration, add `--json` to any command to emit structured JSON logs:
148
+ For programmatic consumption or agent integration, add `--json` before or after the command:
145
149
 
146
150
  ```sh
147
- offckb node --json
148
- offckb node --daemon --json
151
+ offckb --json balance ckt1...
152
+ offckb devnet info --json
149
153
  ```
150
154
 
151
- Each log line is a single JSON object:
155
+ In JSON mode, stdout is reserved for one stable command result. Progress logs are newline-delimited JSON on stderr, and failures use `{ "ok": false, "code", "message" }` with a non-zero exit code. This lets scripts parse stdout without scraping log messages or stack traces:
152
156
 
153
157
  ```json
154
- {"level":"info","message":"Launching CKB devnet Node...","timestamp":"2026-07-07T07:10:00.000Z"}
158
+ { "ok": true, "command": "balance", "network": "devnet", "address": "ckt1...", "ckb": "4200", "udt": [] }
155
159
  ```
156
160
 
157
161
  **RPC & Proxy RPC**
@@ -163,23 +167,34 @@ When the Devnet starts:
163
167
 
164
168
  The proxy RPC server forwards all requests to the RPC server and record every requests while automatically dumping failed transactions for easier debugging.
165
169
 
166
- You can also start a proxy RPC server for public networks:
170
+ You can also start a proxy RPC server for public networks:
167
171
 
168
172
  ```sh
169
173
  offckb node --network <testnet or mainnet>
170
174
  ```
175
+
171
176
  Using a proxy RPC server for Testnet/Mainnet is especially helpful for debugging transactions, since failed transactions are dumped automatically.
172
177
 
173
178
  **Watch Network with TUI**
174
179
 
175
- Once you start the CKB Node, you can use `offckb status --network devnet/testnet/mainnet` to start a CKB-TUI interface to monitor the CKB network from your node.
180
+ Once you start the CKB Node, launch the interactive CKB-TUI for one network:
181
+
182
+ ```sh
183
+ offckb status --network devnet
184
+ offckb status --network testnet
185
+ offckb status --network mainnet
186
+ ```
187
+
188
+ `status` performs a JSON-RPC health check through the proxy before opening the TUI and requires an interactive terminal.
176
189
 
177
190
  ### 2. Create a New Contract Project {#create-project}
178
-
191
+
179
192
  Generate a ready-to-use smart-contract project in JS/TS using templates:
193
+
180
194
  ```sh
181
195
  offckb create <your-project-name> -c <your-contract-name>
182
196
  ```
197
+
183
198
  - The `-c` option is optional, if not provided, the contract name defaults to `hello-world`.
184
199
 
185
200
  **Note for Windows Users:**
@@ -210,10 +225,11 @@ To run mock tests in the generated project, you need to manually install `ckb-de
210
225
  After completing these steps, `npm run test` should pass without mock test failures.
211
226
 
212
227
  ### 3. Deploy Your Contract {#deploy-contract}
213
-
228
+
214
229
  ```sh
215
230
  offckb deploy --network <devnet/testnet> --target <path-to-your-contract-binary-file-or-folder> --output <output-folder-path>
216
231
  ```
232
+
217
233
  - Deployment info is written to the `output-folder-path` you specify.
218
234
 
219
235
  **Upgradable Scripts with `--type-id`**
@@ -224,14 +240,14 @@ offckb deploy --type-id --network <devnet/testnet>
224
240
  ```
225
241
 
226
242
  - **Important**: Upgrades are keyed by the contract‘s artifact name.
227
- - If you plan to upgrade with `--type-id`, do not rename your contract artifact (e.g. keep `hello-world.bc`).
228
- - Renaming it makes the offckb unable to find the previous Type ID info from the `output-folder-path` and will create a new Type ID.
243
+ - If you plan to upgrade with `--type-id`, do not rename your contract artifact (e.g. keep `hello-world.bc`).
244
+ - Renaming it makes the offckb unable to find the previous Type ID info from the `output-folder-path` and will create a new Type ID.
229
245
 
230
246
  ### 4. Debug Your Contract {#debug-contract}
231
-
232
- When you interact with the CKB Devnet through the Proxy RPC server (localhost:28114), any failed transactions are automatically dumped and recorded for debugging.
233
-
234
- **Debug a Transaction:**
247
+
248
+ When you interact with the CKB Devnet through the Proxy RPC server (localhost:28114), any failed transactions are automatically dumped and recorded for debugging.
249
+
250
+ **Debug a Transaction:**
235
251
 
236
252
  ```sh
237
253
  offckb debug --tx-hash <transaction-hash> --network <devnet/testnet>
@@ -283,9 +299,9 @@ offckb debug --tx-hash <tx-hash> --single-script input[0].lock
283
299
  ```
284
300
 
285
301
  All debug utilities are powered by [ckb-debugger](https://github.com/nervosnetwork/ckb-standalone-debugger/tree/develop/ckb-debugger).
286
-
302
+
287
303
  ### 5. Explore Built-in Scripts {#explore-scripts}
288
-
304
+
289
305
  Print all the predefined Scripts for the local blockchain:
290
306
 
291
307
  ```sh
@@ -311,9 +327,9 @@ offckb system-scripts --export-style ccc
311
327
  ```sh
312
328
  offckb system-scripts --output <output-file-path>
313
329
  ```
314
-
330
+
315
331
  ### 6. Tweak Devnet Config {#tweak-devnet-config}
316
-
332
+
317
333
  By default, OffCKB use a fixed Devnet config. You can customize it, for example by modifying the default log level (`warn,ckb-script=debug`).
318
334
 
319
335
  1. Open the interactive Devnet config editor:
@@ -370,6 +386,36 @@ Pay attention to the `devnet.configPath` and `devnet.dataPath`.
370
386
  2. After modifications, run `offckb clean -d` to remove the chain data if needed while keeping the updated config files.
371
387
  3. Restart local blockchain by running `offckb node`
372
388
 
389
+ ### 7. Fork Mainnet/Testnet Into Your Devnet {#fork-devnet}
390
+
391
+ You can fork an existing Mainnet/Testnet data directory into your local devnet, so it keeps the real on-chain state (deployed contracts, cells) while mining locally with Dummy PoW. This implements the same flow as [Devnet From Existing Data](https://docs.nervos.org/docs/node/devnet-from-existing-data).
392
+
393
+ ```sh
394
+ # Point at the directory used by the source node's `ckb -C`:
395
+ offckb devnet fork --from /path/to/ckb-data --dry-run
396
+ offckb devnet fork --from /path/to/ckb-data
397
+ offckb node --daemon
398
+ offckb devnet info
399
+ ```
400
+
401
+ - Database fork mode requires `--from`; it points at the directory the source node runs with (`ckb -C`), which must contain `data/db`. Keeping the source explicit makes large database copies predictable in local scripts and CI.
402
+ - Stop the source node first. Use `--dry-run` to validate the source chain, CKB/DB compatibility, migration requirement, and target without replacing the current devnet.
403
+ - The source chain is auto-detected from the source `ckb.toml`; pass `--source mainnet|testnet` when it cannot be detected, and `--spec-file <path>` to use a local chain spec (e.g. offline).
404
+ - The command copies the chain state (your original data is never modified), deliberately excludes peer store/log/tmp data, imports the matching chain spec, patches it for local mining, verifies the genesis hash, and writes a fork receipt.
405
+ - Fork networking is outbound-isolated: no bootnodes, persisted peers, peer discovery, or outbound peer slots. `offckb devnet info` displays the observed peer count so this property is visible.
406
+ - If `ckb migrate --check` says the database is old, the preflight stops before changing the devnet. Re-run with `--migrate`; only the copied database is migrated.
407
+ - The first `offckb node` run automatically boots with `--skip-spec-check --overwrite-spec`; later runs are normal. Daemon startup waits for healthy CKB RPC, miner spawn, and proxy health before reporting success.
408
+ - Forking replaces the current devnet; use `--force` to replace an existing devnet/fork, or `offckb clean` to reset back to a pure devnet.
409
+
410
+ `offckb devnet info` reports RPC readiness, node tip, Indexer tip/lag, peer count, network isolation, and fork metadata. Balance and signing commands warn while the Indexer is unavailable or behind instead of silently presenting incomplete state.
411
+
412
+ On a forked devnet, `offckb system-scripts`, transfers, deploys and `offckb debug --tx-hash <hash>` work against the real source-chain state, e.g. debugging a failed mainnet transaction fully locally.
413
+
414
+ > [!CAUTION]
415
+ > CKB transactions carry no chain id, so a transaction built on a mainnet fork that spends copied mainnet cells is also valid on mainnet (CKB provides no replay protection). offckb's own flows only use dev keys and fork-mined cells, which cannot replay. Never sign transactions with real mainnet keys against a fork unless you intend to broadcast them yourself.
416
+
417
+ `offckb transfer` fails closed on a Mainnet fork: non-built-in keys require `--allow-mainnet-replay-risk`, and inputs copied from Mainnet are rejected even with that override.
418
+
373
419
  ## Config Setting
374
420
 
375
421
  ### List All Settings
@@ -431,12 +477,21 @@ LOG_LEVEL=debug offckb node
431
477
 
432
478
  ## Accounts
433
479
 
434
- OffCKB comes with 20 pre-funded accounts, each initialized with `42_000_000_00000000` capacity in the genesis block.
480
+ On a pure OffCKB devnet, OffCKB comes with 20 pre-funded accounts, each initialized with `42_000_000_00000000` capacity in the genesis block. A fork keeps the source chain genesis and therefore has no OffCKB genesis allocation; built-in dev accounts are funded by locally mined cellbase cells instead.
481
+
482
+ ```sh
483
+ offckb accounts
484
+ offckb accounts --show-private-keys # trusted local terminals only
485
+ ```
486
+
487
+ On a Mainnet fork, `accounts` re-encodes the same dev lock scripts with the `ckb` address prefix. Once the Indexer is caught up it also reports each account's spendable pure-CKB balance; until then the field is omitted with a warning. Private keys are hidden by default so JSON and agent logs do not collect them.
435
488
 
436
489
  - All private keys are stored in the `account/keys` file.
437
490
  - Detailed information for each account is recorded in `account/account.json`.
438
491
  - When deploying contracts, the deployment cost are automatically deducted from these pre-funded accounts. This allows you to test deployments without faucets or manual funding.
439
492
 
493
+ For commands that accept a private key, prefer `--privkey-file <path>` or `OFFCKB_PRIVATE_KEY` over `--privkey`, which is visible in shell history and process listings.
494
+
440
495
  :warning: **DO NOT SEND REAL ASSETS TO THESE ACCOUNTS. THE KEYS ARE PUBLIC, AND YOU MAY LOSE YOUR MONEY** :warning:
441
496
 
442
497
  ## About CCC
@@ -455,4 +510,3 @@ npm install -g @offckb/cli
455
510
  ## Contributing
456
511
 
457
512
  check [development doc](/docs/develop.md)
458
-