@offckb/cli 0.4.2-canary-962a883.0 → 0.4.2-canary-451da89.0

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.
package/README.md CHANGED
@@ -24,12 +24,12 @@ There are BREAKING CHANGES between v0.3.x and v0.4.x, make sure to read the [mig
24
24
  - [Install](#install)
25
25
  - [Usage](#usage)
26
26
  - [Get started](#get-started)
27
- - [Run a Local CKB Devnet](#running-ckb)
28
- - [Create a CKB Smart Contract Project](#create-project)
29
- - [Deploy a CKB Smart Contract](#deploy-contract)
30
- - [Debug a CKB Smart Contract](#debug-contract)
31
- - [Explore built-in Scripts info](#explore-scripts)
32
- - [Tweak Devnet Config](#tweak-devnet-config)
27
+ - [1. Run a Local CKB Devnet {#running-ckb}](#1-run-a-local-ckb-devnet-running-ckb)
28
+ - [2. Create a New Contract Project {#create-project}](#2-create-a-new-contract-project-create-project)
29
+ - [3. Deploy Your Contract {#deploy-contract}](#3-deploy-your-contract-deploy-contract)
30
+ - [4. Debug Your Contract {#debug-contract}](#4-debug-your-contract-debug-contract)
31
+ - [5. Explore Built-in Scripts {#explore-scripts}](#5-explore-built-in-scripts-explore-scripts)
32
+ - [6. Tweak Devnet Config {#tweak-devnet-config}](#6-tweak-devnet-config-tweak-devnet-config)
33
33
  - [Config Setting](#config-setting)
34
34
  - [List All Settings](#list-all-settings)
35
35
  - [Set CKB version](#set-ckb-version)
@@ -107,6 +107,15 @@ Or set a default version globally:
107
107
  offckb config set ckb-version 0.201.0
108
108
  offckb node
109
109
  ```
110
+
111
+ Or specify the path to your locally compiled CKB binary:
112
+
113
+ ```sh
114
+ offckb node --binary-path /path/to/your/ckb/binary
115
+ ```
116
+
117
+ When using `--binary-path`, it will ignore the specified version and network, and only work for devnet.
118
+
110
119
  **RPC & Proxy RPC**
111
120
 
112
121
  When the Devnet starts:
@@ -125,7 +134,7 @@ Using a proxy RPC server for Testnet/Mainnet is especially helpful for debugging
125
134
 
126
135
  ### 2. Create a New Contract Project {#create-project}
127
136
 
128
- Generate a ready-to-use project in JS/TS using templates:
137
+ Generate a ready-to-use smart-contract project in JS/TS using templates:
129
138
  ```sh
130
139
  offckb create <your-project-name> -c <your-contract-name>
131
140
  ```
package/build/index.js CHANGED
@@ -332,8 +332,9 @@ program
332
332
  .command('node [CKB-Version]')
333
333
  .description('Use the CKB to start devnet')
334
334
  .option('--network <network>', 'Specify the network to deploy to', 'devnet')
335
+ .option('-b, --binary-path <binaryPath>', 'Specify the CKB binary path to use, only for devnet, when set, will ignore version and network')
335
336
  .action((version, options) => __awaiter(void 0, void 0, void 0, function* () {
336
- return (0, node_1.startNode)({ version, network: options.network });
337
+ return (0, node_1.startNode)({ version, network: options.network, binaryPath: options.binaryPath });
337
338
  }));
338
339
  program
339
340
  .command('create [project-name]')
@@ -355,6 +356,7 @@ program
355
356
  .option('-o, --output <output>', 'Specify the output folder path for the deployment record files', './deployment')
356
357
  .option('-t, --type-id', 'Specify if use upgradable type id to deploy the script')
357
358
  .option('--privkey <privkey>', 'Specify the private key to deploy scripts')
359
+ .option('-y, --yes', 'Skip confirmation prompt and deploy immediately')
358
360
  .action((options) => (0, deploy_1.deploy)(options));
359
361
  program
360
362
  .command('debug')
@@ -1137,12 +1139,15 @@ function deploy() {
1137
1139
  ` šŸ”‘ Using ${opt.privkey ? 'custom' : 'default'} private key`,
1138
1140
  ` šŸ”„ Type ID: ${enableTypeId ? 'enabled (upgradable)' : 'disabled (immutable)'}`,
1139
1141
  ]);
1140
- const res = yield (0, prompts_1.confirm)({
1141
- message: 'Are you sure you want to deploy these contracts?',
1142
- });
1143
- if (!res) {
1144
- logger_1.logger.info('Deployment cancelled.');
1145
- return;
1142
+ // Skip confirmation if -y flag is provided
1143
+ if (!opt.yes) {
1144
+ const res = yield (0, prompts_1.confirm)({
1145
+ message: 'Are you sure you want to deploy these contracts?',
1146
+ });
1147
+ if (!res) {
1148
+ logger_1.logger.info('Deployment cancelled.');
1149
+ return;
1150
+ }
1146
1151
  }
1147
1152
  const results = yield (0, deploy_1.deployBinaries)(outputFolder, binPaths, privateKey, enableTypeId, ckb);
1148
1153
  logger_1.logger.info('');
@@ -1286,10 +1291,13 @@ const encoding_1 = __nccwpck_require__(6851);
1286
1291
  const rpc_proxy_1 = __nccwpck_require__(46589);
1287
1292
  const base_1 = __nccwpck_require__(69951);
1288
1293
  const logger_1 = __nccwpck_require__(65370);
1289
- function startNode({ version, network = base_1.Network.devnet }) {
1294
+ function startNode({ version, network = base_1.Network.devnet, binaryPath }) {
1295
+ if (binaryPath && network !== base_1.Network.devnet) {
1296
+ logger_1.logger.warn('Custom binaryPath is only supported for devnet. The provided binaryPath will be ignored.');
1297
+ }
1290
1298
  switch (network) {
1291
1299
  case base_1.Network.devnet:
1292
- return nodeDevnet({ version });
1300
+ return nodeDevnet({ version, binaryPath });
1293
1301
  case base_1.Network.testnet:
1294
1302
  return nodeTestnet();
1295
1303
  case base_1.Network.mainnet:
@@ -1299,13 +1307,20 @@ function startNode({ version, network = base_1.Network.devnet }) {
1299
1307
  }
1300
1308
  }
1301
1309
  function nodeDevnet(_a) {
1302
- return __awaiter(this, arguments, void 0, function* ({ version }) {
1310
+ return __awaiter(this, arguments, void 0, function* ({ version, binaryPath }) {
1303
1311
  var _b, _c;
1304
1312
  const settings = (0, setting_1.readSettings)();
1305
1313
  const ckbVersion = version || settings.bins.defaultCKBVersion;
1306
- yield (0, install_1.installCKBBinary)(ckbVersion);
1314
+ let ckbBinPath = '';
1315
+ if (binaryPath) {
1316
+ ckbBinPath = (0, encoding_1.encodeBinPathForTerminal)(binaryPath);
1317
+ logger_1.logger.info(`Using custom CKB binary path: ${ckbBinPath}`);
1318
+ }
1319
+ else {
1320
+ yield (0, install_1.installCKBBinary)(ckbVersion);
1321
+ ckbBinPath = (0, encoding_1.encodeBinPathForTerminal)((0, setting_1.getCKBBinaryPath)(ckbVersion));
1322
+ }
1307
1323
  yield (0, init_chain_1.initChainIfNeeded)();
1308
- const ckbBinPath = (0, encoding_1.encodeBinPathForTerminal)((0, setting_1.getCKBBinaryPath)(ckbVersion));
1309
1324
  const devnetConfigPath = (0, encoding_1.encodeBinPathForTerminal)(settings.devnet.configPath);
1310
1325
  const ckbCmd = `${ckbBinPath} run -C ${devnetConfigPath}`;
1311
1326
  const minerCmd = `${ckbBinPath} miner -C ${devnetConfigPath}`;
@@ -1471,7 +1486,7 @@ function systemCellToScriptInfo({ cell, depType, depGroup, extraCellDeps, }) {
1471
1486
  }
1472
1487
  return {
1473
1488
  codeHash: (cell.type_hash || cell.data_hash),
1474
- hashType: cell.type_hash ? 'type' : 'data1',
1489
+ hashType: cell.type_hash ? 'type' : 'data2',
1475
1490
  cellDeps,
1476
1491
  };
1477
1492
  }
@@ -1495,7 +1510,7 @@ function systemCellToScriptInfo({ cell, depType, depGroup, extraCellDeps, }) {
1495
1510
  }
1496
1511
  return {
1497
1512
  codeHash: (cell.type_hash || cell.data_hash),
1498
- hashType: cell.type_hash ? 'type' : 'data1',
1513
+ hashType: cell.type_hash ? 'type' : 'data2',
1499
1514
  cellDeps,
1500
1515
  };
1501
1516
  }
@@ -2797,7 +2812,7 @@ exports.TESTNET_SYSTEM_SCRIPTS = {
2797
2812
  name: 'secp256k1_blake160_multisig_all_v2',
2798
2813
  script: {
2799
2814
  codeHash: '0x36c971b8d41fbd94aabca77dc75e826729ac98447b46f91e00796155dddb0d29',
2800
- hashType: 'data1',
2815
+ hashType: 'data2',
2801
2816
  cellDeps: [
2802
2817
  {
2803
2818
  cellDep: {
@@ -2921,7 +2936,7 @@ exports.MAINNET_SYSTEM_SCRIPTS = {
2921
2936
  name: 'secp256k1_blake160_multisig_all_v2',
2922
2937
  script: {
2923
2938
  codeHash: '0x36c971b8d41fbd94aabca77dc75e826729ac98447b46f91e00796155dddb0d29',
2924
- hashType: 'data1',
2939
+ hashType: 'data2',
2925
2940
  cellDeps: [
2926
2941
  {
2927
2942
  cellDep: {
@@ -3025,7 +3040,7 @@ function getScriptInfoFrom(recipe) {
3025
3040
  const isDepCode = recipe.depGroupRecipes.length > 0;
3026
3041
  const scriptsInfo = {
3027
3042
  codeHash: (firstCell.typeId ? firstCell.typeId : firstCell.dataHash),
3028
- hashType: firstCell.typeId ? 'type' : 'data1',
3043
+ hashType: firstCell.typeId ? 'type' : 'data2',
3029
3044
  cellDeps: !isDepCode
3030
3045
  ? [
3031
3046
  {
@@ -3373,16 +3388,32 @@ exports.networks = {
3373
3388
  "use strict";
3374
3389
 
3375
3390
  Object.defineProperty(exports, "__esModule", ({ value: true }));
3376
- exports.BASE_TEMPLATE_METADATA = exports.TEMPLATE_CONFIG = void 0;
3377
- exports.TEMPLATE_CONFIG = {
3391
+ exports.REQUIRED_FILES = exports.PACKAGE_JSON_CONFIG = void 0;
3392
+ exports.PACKAGE_JSON_CONFIG = {
3393
+ version: '0.1.0',
3394
+ description: 'CKB JavaScript Smart Contract project',
3395
+ private: true,
3396
+ type: 'module',
3397
+ scripts: {
3398
+ 'build:contract': 'node scripts/build-contract.js',
3399
+ 'build:contract:debug': 'node scripts/build-contract.js --debug',
3400
+ build: 'node scripts/build-all.js',
3401
+ 'build:debug': 'node scripts/build-all.js --debug',
3402
+ deploy: 'node scripts/build-all.js && node scripts/deploy.js',
3403
+ 'deploy:debug': 'node scripts/build-all.js --debug && node scripts/deploy.js',
3404
+ test: 'node scripts/build-all.js && jest',
3405
+ 'add-contract': 'node scripts/add-contract.js',
3406
+ clean: 'rimraf dist',
3407
+ format: 'prettier --write .',
3408
+ },
3378
3409
  dependencies: {
3379
3410
  '@ckb-js-std/bindings': '~1.0.0',
3380
3411
  '@ckb-js-std/core': '~1.0.0',
3381
3412
  dotenv: '^17.2.1',
3382
3413
  },
3383
3414
  devDependencies: {
3384
- 'ckb-testtool': '1.0.3',
3385
- '@ckb-ccc/core': '1.5.3', // lock to version compatible with ckb-testtool
3415
+ 'ckb-testtool': '1.0.5',
3416
+ '@ckb-ccc/core': '1.12.2', // lock to version compatible with ckb-testtool
3386
3417
  esbuild: '~0.25.8',
3387
3418
  jest: '~29.7.0',
3388
3419
  prettier: '^3.5.3',
@@ -3395,25 +3426,16 @@ exports.TEMPLATE_CONFIG = {
3395
3426
  '@types/jest': '~29.5.14',
3396
3427
  },
3397
3428
  };
3398
- exports.BASE_TEMPLATE_METADATA = {
3399
- name: 'ckb-js-vm-base',
3400
- description: 'Base template for CKB JavaScript VM projects',
3401
- supportedLanguages: ['typescript', 'javascript'],
3402
- requiredFiles: [
3403
- 'package.json.template',
3404
- 'jest.config.cjs.template',
3405
- 'gitignore.template',
3406
- 'README.md.template',
3407
- 'deployment/scripts.json.template',
3408
- 'deployment/README.md.template',
3409
- 'env.example.template',
3410
- 'env.template',
3411
- ],
3412
- conditionalFiles: {
3413
- typescript: ['tsconfig.json.template', 'tsconfig.base.json.template'],
3414
- javascript: [],
3415
- },
3416
- };
3429
+ exports.REQUIRED_FILES = [
3430
+ 'package.json.template',
3431
+ 'jest.config.cjs.template',
3432
+ 'gitignore.template',
3433
+ 'README.md.template',
3434
+ 'deployment/scripts.json.template',
3435
+ 'deployment/README.md.template',
3436
+ 'env.example.template',
3437
+ 'env.template',
3438
+ ];
3417
3439
 
3418
3440
 
3419
3441
  /***/ }),
@@ -3647,6 +3669,9 @@ class TemplateProcessor {
3647
3669
  processed = processed.replace(/\{\{PROJECT_PATH\}\}/g, context.projectPath || '.');
3648
3670
  processed = processed.replace(/\{\{CONTRACT_NAME\}\}/g, context.contractName || 'hello-world');
3649
3671
  processed = processed.replace(/\{\{LANGUAGE\}\}/g, context.language);
3672
+ // Add LANGUAGE_EXT variable for file extensions (typescript -> ts, javascript -> js)
3673
+ const languageExtension = context.language === 'typescript' ? 'ts' : 'js';
3674
+ processed = processed.replace(/\{\{LANGUAGE_EXT\}\}/g, languageExtension);
3650
3675
  processed = processed.replace(/\{\{PACKAGE_MANAGER\}\}/g, context.packageManager);
3651
3676
  return processed;
3652
3677
  }
@@ -3661,7 +3686,7 @@ class TemplateProcessor {
3661
3686
  return false;
3662
3687
  }
3663
3688
  // Always include required files
3664
- if (config_1.BASE_TEMPLATE_METADATA.requiredFiles.some((reqFile) => relativePath.includes(reqFile))) {
3689
+ if (config_1.REQUIRED_FILES.some((reqFile) => relativePath.includes(reqFile))) {
3665
3690
  return true;
3666
3691
  }
3667
3692
  // Handle language-specific jest config files
@@ -3705,25 +3730,16 @@ class TemplateProcessor {
3705
3730
  generatePackageJson(context) {
3706
3731
  const basePackageJson = {
3707
3732
  name: context.projectName,
3708
- version: '0.1.0',
3709
- description: 'CKB JavaScript Smart Contract project',
3710
- private: true,
3711
- type: 'module',
3712
- scripts: {
3713
- build: 'node scripts/build-all.js',
3714
- 'build:contract': 'node scripts/build-contract.js',
3715
- test: 'node scripts/build-all.js && jest',
3716
- 'add-contract': 'node scripts/add-contract.js',
3717
- deploy: 'node scripts/build-all.js && node scripts/deploy.js',
3718
- clean: 'rimraf dist',
3719
- format: 'prettier --write .',
3720
- },
3721
- dependencies: config_1.TEMPLATE_CONFIG.dependencies,
3722
- devDependencies: Object.assign({}, config_1.TEMPLATE_CONFIG.devDependencies),
3733
+ version: config_1.PACKAGE_JSON_CONFIG.version,
3734
+ description: config_1.PACKAGE_JSON_CONFIG.description,
3735
+ private: config_1.PACKAGE_JSON_CONFIG.private,
3736
+ type: config_1.PACKAGE_JSON_CONFIG.type,
3737
+ scripts: config_1.PACKAGE_JSON_CONFIG.scripts,
3738
+ dependencies: config_1.PACKAGE_JSON_CONFIG.dependencies,
3739
+ devDependencies: Object.assign({}, config_1.PACKAGE_JSON_CONFIG.devDependencies),
3723
3740
  };
3724
- // Add TypeScript dependencies if needed
3725
3741
  if (context.language === 'typescript') {
3726
- Object.assign(basePackageJson.devDependencies, config_1.TEMPLATE_CONFIG.typescriptDevDeps);
3742
+ Object.assign(basePackageJson.devDependencies, config_1.PACKAGE_JSON_CONFIG.typescriptDevDeps);
3727
3743
  }
3728
3744
  return basePackageJson;
3729
3745
  }
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@offckb/cli",
3
- "version": "0.4.2-canary-962a883.0",
3
+ "version": "0.4.2-canary-451da89.0",
4
4
  "description": "ckb development network for your first try",
5
5
  "author": "CKB EcoFund",
6
6
  "license": "MIT",
@@ -13,9 +13,9 @@ This project uses the CKB JavaScript VM (ckb-js-vm) to write smart contracts in
13
13
  ā”œā”€ā”€ contracts/ # Smart contract source code
14
14
  │ └── hello-world/
15
15
  │ └── src/
16
- │ └── index.{{LANGUAGE}} # Contract implementation
16
+ │ └── index.{{LANGUAGE_EXT}} # Contract implementation
17
17
  ā”œā”€ā”€ tests/ # Contract tests
18
- │ └── hello-world.test.{{LANGUAGE}}
18
+ │ └── hello-world.test.{{LANGUAGE_EXT}}
19
19
  ā”œā”€ā”€ scripts/ # Build and utility scripts
20
20
  │ ā”œā”€ā”€ build-all.js
21
21
  │ ā”œā”€ā”€ build-contract.js
@@ -56,6 +56,15 @@ Build a specific contract:
56
56
  {{PACKAGE_MANAGER}} run build:contract hello-world
57
57
  ```
58
58
 
59
+ Build with debug version:
60
+ ```bash
61
+ {{PACKAGE_MANAGER}} run build:debug
62
+ ```
63
+ or for specific contract with debug enabled:
64
+ ```bash
65
+ {{PACKAGE_MANAGER}} run build:contract:debug hello-world
66
+ ```
67
+
59
68
  ### Running Tests
60
69
 
61
70
  Run all tests:
@@ -84,7 +93,7 @@ This will:
84
93
 
85
94
  ### Contract Development
86
95
 
87
- 1. Edit your contract in `contracts/<contract-name>/src/index.{{LANGUAGE}}`
96
+ 1. Edit your contract in `contracts/<contract-name>/src/index.{{LANGUAGE_EXT}}`
88
97
  2. Build the contract: `{{PACKAGE_MANAGER}} run build:contract <contract-name>`
89
98
  3. Run tests: `{{PACKAGE_MANAGER}} test -- <contract-name>`
90
99
 
@@ -106,9 +115,12 @@ Tests use the `ckb-testtool` framework to simulate CKB blockchain execution. Eac
106
115
 
107
116
  - `build` - Build all contracts
108
117
  - `build:contract <name>` - Build a specific contract
118
+ - `build:debug` - Build all contracts with debug version
119
+ - `build:contract:debug <name>` - Build a specific contract with debug version
109
120
  - `test` - Run all tests
110
121
  - `add-contract <name>` - Add a new contract
111
122
  - `deploy` - Deploy contracts to CKB network
123
+ - `deploy:debug` - Deploy contracts with debug version to CKB network
112
124
  - `clean` - Remove all build outputs
113
125
  - `format` - Format code with Prettier
114
126
 
@@ -129,6 +141,8 @@ Deploy your contracts to CKB networks using the built-in deploy script:
129
141
  {{PACKAGE_MANAGER}} run deploy -- --network mainnet
130
142
  ```
131
143
 
144
+ Note that you can change the `run deploy` to `run deploy:debug` to deploy the debug version of your smart contracts.
145
+
132
146
  ### Advanced Options
133
147
 
134
148
  ```bash
@@ -4,7 +4,7 @@ import fs from 'fs';
4
4
  import path from 'path';
5
5
  import { execSync } from 'child_process';
6
6
 
7
- function buildAllContracts() {
7
+ function buildAllContracts(isDebug = false) {
8
8
  const contractsDir = path.join(process.cwd(), 'contracts');
9
9
 
10
10
  if (!fs.existsSync(contractsDir)) {
@@ -27,8 +27,8 @@ function buildAllContracts() {
27
27
  for (const contractName of contracts) {
28
28
  console.log(`\nšŸ“¦ Building contract: ${contractName}`);
29
29
  try {
30
- execSync(`node scripts/build-contract.js ${contractName}`, { stdio: 'inherit' });
31
- console.log(`āœ… Successfully built: ${contractName}`);
30
+ execSync(`node scripts/build-contract.js ${contractName} ${isDebug ? '--debug' : ''}`, { stdio: 'inherit' });
31
+ console.log(`āœ… Successfully built: ${contractName} with ${isDebug ? 'debug' : 'release'} version`);
32
32
  } catch (error) {
33
33
  console.error(`āŒ Failed to build: ${contractName}`);
34
34
  console.error(error.message);
@@ -39,4 +39,4 @@ function buildAllContracts() {
39
39
  console.log(`\nšŸŽ‰ All contracts built successfully!`);
40
40
  }
41
41
 
42
- buildAllContracts();
42
+ buildAllContracts(process.argv.includes('--debug'));
@@ -4,7 +4,7 @@ import { execSync } from 'child_process';
4
4
  import path from 'path';
5
5
  import fs from 'fs';
6
6
 
7
- function buildContract(contractName) {
7
+ function buildContract(contractName, isDebug = false) {
8
8
  if (!contractName) {
9
9
  console.error('Usage: node build-contract.js <contract-name>');
10
10
  process.exit(1);
@@ -50,14 +50,23 @@ function buildContract(contractName) {
50
50
  // }
51
51
 
52
52
  // Step 2: Bundle with esbuild
53
- console.log(' šŸ“¦ Bundling with esbuild...');
53
+ console.log(` šŸ“¦ Bundling with esbuild with ${isDebug ? 'debug' : 'release'} settings...`);
54
+ const debugParams = [
55
+ '--sourcemap=external',
56
+ '--sources-content',
57
+ '--keep-names',
58
+ '--minify=false',
59
+ '--define:DEBUG=true',
60
+ '--loader:.map=json',
61
+ ];
62
+ const releaseParams = ['--minify'];
54
63
  const esbuildCmd = [
55
64
  './node_modules/.bin/esbuild',
56
65
  '--platform=neutral',
57
- '--minify',
58
66
  '--bundle',
59
67
  '--external:@ckb-js-std/bindings',
60
68
  '--target=es2022',
69
+ ...(isDebug ? debugParams : releaseParams),
61
70
  srcFile,
62
71
  `--outfile=${outputJsFile}`,
63
72
  ].join(' ');
@@ -87,5 +96,7 @@ function buildContract(contractName) {
87
96
  }
88
97
 
89
98
  // Get contract name from command line arguments
90
- const contractName = process.argv[2];
91
- buildContract(contractName);
99
+ const isDebug = process.argv.includes('--debug');
100
+ const args = process.argv.slice(2).filter((arg) => arg !== '--debug');
101
+ const contractName = args[0];
102
+ buildContract(contractName, isDebug);