@offckb/cli 0.3.0-canary-34f0d45.0 → 0.3.0-canary-5f5a3b5.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
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
**CKB local development network for your first try.**
|
|
10
10
|
|
|
11
11
|
- One-line command to start a devnet
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
12
|
+
- No docker required
|
|
13
|
+
- Pre-funded test accounts
|
|
14
|
+
- Built-in scripts like [Omnilock](https://github.com/cryptape/omnilock) and [Spore-contract](https://github.com/sporeprotocol/spore-contract)
|
|
15
|
+
- Multiple minimal dApp templates to learn and get your hands dirty
|
|
16
16
|
|
|
17
17
|
Start building on CKB blockchain, right now, right away!
|
|
18
18
|
|
|
@@ -23,8 +23,14 @@ Start building on CKB blockchain, right now, right away!
|
|
|
23
23
|
- [Install](#install)
|
|
24
24
|
- [Usage](#usage)
|
|
25
25
|
- [Get started](#get-started)
|
|
26
|
+
- [Running CKB](#running-ckb)
|
|
27
|
+
- [List scripts info](#list-scripts-info)
|
|
26
28
|
- [Create a full-stack Project](#create-a-full-stack-project)
|
|
27
29
|
- [Create a script-only Project](#create-a-script-only-project)
|
|
30
|
+
- [Build and Deploy a script](#build-and-deploy-a-script)
|
|
31
|
+
- [Start the frontend project](#start-the-frontend-project)
|
|
32
|
+
- [Debug a transaction](#debug-a-transaction)
|
|
33
|
+
- [Generate Moleculec bindings](#generate-moleculec-bindings)
|
|
28
34
|
- [Config Setting](#config-setting)
|
|
29
35
|
- [List All Settings](#list-all-settings)
|
|
30
36
|
- [Set CKB version](#set-ckb-version)
|
|
@@ -61,8 +67,8 @@ Commands:
|
|
|
61
67
|
clean Clean the devnet data, need to stop running the chain first
|
|
62
68
|
accounts Print account list info
|
|
63
69
|
list-hashes [CKB-Version] Use the CKB to list blockchain scripts hashes
|
|
64
|
-
inject-config Add offckb.config.ts to your workspace
|
|
65
|
-
sync-
|
|
70
|
+
inject-config Add offckb.config.ts to your frontend workspace
|
|
71
|
+
sync-scripts Sync scripts json file in your frontend workspace
|
|
66
72
|
deposit [options] [toAddress] [amountInShannon] Deposit CKB tokens to address, only devnet and testnet
|
|
67
73
|
transfer [options] [toAddress] [amountInShannon] Transfer CKB tokens to address, only devnet and testnet
|
|
68
74
|
balance [options] [toAddress] Check account balance, only devnet and testnet
|
|
@@ -79,6 +85,61 @@ Commands:
|
|
|
79
85
|
|
|
80
86
|
## Get started
|
|
81
87
|
|
|
88
|
+
### Running CKB
|
|
89
|
+
|
|
90
|
+
Start a local blockchain with the default CKB version:
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
offckb node
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Or specify a CKB version:
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
offckb node 0.117.0
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Or set the default CKB version:
|
|
103
|
+
|
|
104
|
+
```sh
|
|
105
|
+
offckb config set ckb-version 0.117.0
|
|
106
|
+
offckb node
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Once you start the devnet, there is a RPC server running at `http://localhost:8114`. There is also a RPC proxy server running at `http://localhost:9000` which will proxy all the requests to the RPC server. The meaning of using a proxy RPC server is to record request and automatically dump failed transactions so you can debug them easily later.
|
|
110
|
+
|
|
111
|
+
The proxy server is optional, you can use the RPC server directly if you don't need a proxy:
|
|
112
|
+
|
|
113
|
+
```sh
|
|
114
|
+
offckb node --no-proxy
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Or start the proxy server in a standalone terminal to better monitor the logs:
|
|
118
|
+
|
|
119
|
+
```sh
|
|
120
|
+
offckb proxy-rpc --ckb-rpc http://localhost:8114 --port 9000 --network devnet
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### List scripts info
|
|
124
|
+
|
|
125
|
+
List all the predefined scripts for the local blockchain:
|
|
126
|
+
|
|
127
|
+
```sh
|
|
128
|
+
offckb system-scripts
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Or export the scripts info to a lumos JSON file:
|
|
132
|
+
|
|
133
|
+
```sh
|
|
134
|
+
offckb system-scripts --export-style lumos
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Or print the scripts info in a CCC style:
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
offckb system-scripts --export-style ccc
|
|
141
|
+
```
|
|
142
|
+
|
|
82
143
|
### Create a full-stack Project
|
|
83
144
|
|
|
84
145
|
Create a new project from predefined boilerplates.
|
|
@@ -99,6 +160,86 @@ offckb create <your-project-name> --script
|
|
|
99
160
|
|
|
100
161
|
Note: you need to have rust/cargo/cargo-generate/clang 16+ installed in your environment to use this command. offckb doesn't do anything really, it just call [ckb-script-template](https://github.com/cryptape/ckb-script-tempaltes) to do all the magic.
|
|
101
162
|
|
|
163
|
+
### Build and Deploy a script
|
|
164
|
+
|
|
165
|
+
The fullstack boilerplate project is a monorepo, which contains a script project and a frontend project.
|
|
166
|
+
|
|
167
|
+
To build the script, in the root of the project, run:
|
|
168
|
+
|
|
169
|
+
```sh
|
|
170
|
+
make build
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
To deploy the script, cd into the frontend folder and run:
|
|
174
|
+
|
|
175
|
+
```sh
|
|
176
|
+
cd frontend && offckb deploy --network <devnet/testnet>
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Once the deployment is done, you can use the following command to check the deployed scripts:
|
|
180
|
+
|
|
181
|
+
```sh
|
|
182
|
+
offckb my-scripts --network <devnet/testnet>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Your deployed scripts will be also be listed in the `frontend/offckb/my-scripts` folder in your frontend project.
|
|
186
|
+
|
|
187
|
+
### Start the frontend project
|
|
188
|
+
|
|
189
|
+
To start the frontend project, cd into the frontend folder and run:
|
|
190
|
+
|
|
191
|
+
```sh
|
|
192
|
+
npm i & npm run dev
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Debug a transaction
|
|
196
|
+
|
|
197
|
+
If you are using the proxy RPC server, all the failed transactions will be dumped and recorded so you can debug them later.
|
|
198
|
+
|
|
199
|
+
Everytime you run a transaction, you can debug it with the transaction hash:
|
|
200
|
+
|
|
201
|
+
```sh
|
|
202
|
+
offckb debug <transaction-hash>
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
If you want to debug a single cell script in the transaction, you can use the following command:
|
|
206
|
+
|
|
207
|
+
```sh
|
|
208
|
+
offckb debug <transaction-hash> --single-script <single-cell-script-option>
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
The `single-cell-script-option` format is `<cell-type>[<cell-index>].<script-type>`, eg: `"input[0].lock"`
|
|
212
|
+
|
|
213
|
+
- `cell-type` could be `input` or `output`, refers to the cell type
|
|
214
|
+
- `cell-index` is the index of the cell in the transaction
|
|
215
|
+
- `script-type` could be `lock` or `type`, refers to the script type
|
|
216
|
+
|
|
217
|
+
Or you can replace the script with a binary file in your single cell script debug session:
|
|
218
|
+
|
|
219
|
+
```sh
|
|
220
|
+
offckb debug <transaction-hash> --single-script <single-cell-script-option> --bin <path/to/binary/file>
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
All the debug utils are borrowed from [ckb-debugger](https://github.com/nervosnetwork/ckb-debugger).
|
|
224
|
+
|
|
225
|
+
### Generate Moleculec bindings
|
|
226
|
+
|
|
227
|
+
[Moleculec](https://github.com/nervosnetwork/molecule) is the official Serialization/Deserialization system for CKB smart contracts.
|
|
228
|
+
|
|
229
|
+
You will define your data structure in `.mol` file(schema), and generate the bindings for different programming languages to use in your development.
|
|
230
|
+
|
|
231
|
+
```sh
|
|
232
|
+
offckb mol --schema <path/to/mol/file> --output <path/to/output/file> --lang <lang>
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
The `lang` could be `ts`, `js`, `c`, `rs` and `go`.
|
|
236
|
+
|
|
237
|
+
If you have multiple `.mol` files, you can use a folder as the input and specify an output folder:
|
|
238
|
+
|
|
239
|
+
```sh
|
|
240
|
+
offckb mol --schema <path/to/mol/folder> --output-folder <path/to/output/folder> --lang <lang>
|
|
241
|
+
```
|
|
242
|
+
|
|
102
243
|
## Config Setting
|
|
103
244
|
|
|
104
245
|
### List All Settings
|
package/dist/cli.js
CHANGED
|
@@ -42,7 +42,7 @@ const encoding_1 = require("./util/encoding");
|
|
|
42
42
|
const inject_config_1 = require("./cmd/inject-config");
|
|
43
43
|
const deposit_1 = require("./cmd/deposit");
|
|
44
44
|
const deploy_1 = require("./cmd/deploy");
|
|
45
|
-
const
|
|
45
|
+
const sync_scripts_1 = require("./cmd/sync-scripts");
|
|
46
46
|
const transfer_1 = require("./cmd/transfer");
|
|
47
47
|
const balance_1 = require("./cmd/balance");
|
|
48
48
|
const create_1 = require("./cmd/create");
|
|
@@ -94,8 +94,8 @@ program
|
|
|
94
94
|
.command('list-hashes [CKB-Version]')
|
|
95
95
|
.description('Use the CKB to list blockchain scripts hashes')
|
|
96
96
|
.action(list_hashes_1.listHashes);
|
|
97
|
-
program.command('inject-config').description('Add offckb.config.ts to your workspace').action(inject_config_1.injectConfig);
|
|
98
|
-
program.command('sync-
|
|
97
|
+
program.command('inject-config').description('Add offckb.config.ts to your frontend workspace').action(inject_config_1.injectConfig);
|
|
98
|
+
program.command('sync-scripts').description('Sync scripts json files in your frontend workspace').action(sync_scripts_1.syncScripts);
|
|
99
99
|
program
|
|
100
100
|
.command('deposit [toAddress] [amountInShannon]')
|
|
101
101
|
.description('Deposit CKB tokens to address, only devnet and testnet')
|
package/dist/cmd/config.js
CHANGED
|
@@ -70,11 +70,12 @@ function Config(action, item, value) {
|
|
|
70
70
|
const settings = (0, setting_1.readSettings)();
|
|
71
71
|
try {
|
|
72
72
|
if ((0, validator_1.isValidVersion)(value)) {
|
|
73
|
-
|
|
73
|
+
const version = extractVersion(value);
|
|
74
|
+
settings.bins.defaultCKBVersion = version;
|
|
74
75
|
return (0, setting_1.writeSettings)(settings);
|
|
75
76
|
}
|
|
76
77
|
else {
|
|
77
|
-
return console.error(`invalid version value,
|
|
78
|
+
return console.error(`invalid version value, ${value}. Check available versions on https://github.com/nervosnetwork/ckb/tags`);
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
catch (error) {
|
|
@@ -100,3 +101,7 @@ function Config(action, item, value) {
|
|
|
100
101
|
});
|
|
101
102
|
}
|
|
102
103
|
exports.Config = Config;
|
|
104
|
+
function extractVersion(version) {
|
|
105
|
+
// If the version starts with 'v', remove it
|
|
106
|
+
return version.startsWith('v') ? version.slice(1) : version;
|
|
107
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function syncScripts(): void;
|
|
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.syncScripts = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const validator_1 = require("../util/validator");
|
|
9
9
|
const gen_1 = require("../scripts/gen");
|
|
10
10
|
const offckb_config_1 = require("../template/offckb-config");
|
|
11
|
-
function
|
|
11
|
+
function syncScripts() {
|
|
12
12
|
(0, validator_1.validateExecDappEnvironment)();
|
|
13
13
|
const userOffCKBConfigPath = path_1.default.resolve(process.cwd(), 'offckb.config.ts');
|
|
14
14
|
const contractInfoFolder = offckb_config_1.OffCKBConfigFile.readContractInfoFolder(userOffCKBConfigPath);
|
|
@@ -21,4 +21,4 @@ function syncConfig() {
|
|
|
21
21
|
(0, gen_1.genMyScriptsJsonFile)(myScriptsJsonFilePath);
|
|
22
22
|
console.log('scripts json config updated.');
|
|
23
23
|
}
|
|
24
|
-
exports.
|
|
24
|
+
exports.syncScripts = syncScripts;
|
package/dist/util/validator.js
CHANGED
|
@@ -60,8 +60,8 @@ function isValidVersion(version) {
|
|
|
60
60
|
if (typeof version !== 'string') {
|
|
61
61
|
return false;
|
|
62
62
|
}
|
|
63
|
-
// Regular expression to match version strings like X.Y.Z
|
|
64
|
-
const versionRegex =
|
|
63
|
+
// Regular expression to match version strings like X.Y.Z or vX.Y.Z-rcN
|
|
64
|
+
const versionRegex = /^v?\d+\.\d+\.\d+(-rc\d+)?$/;
|
|
65
65
|
// Test the version against the regex
|
|
66
66
|
return versionRegex.test(version);
|
|
67
67
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@offckb/cli",
|
|
3
|
-
"version": "0.3.0-canary-
|
|
3
|
+
"version": "0.3.0-canary-5f5a3b5.0",
|
|
4
4
|
"description": "ckb development network for your first try",
|
|
5
|
-
"author": "
|
|
5
|
+
"author": "CKB EcoFund",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/
|
|
9
|
+
"url": "git+https://github.com/ckb-ecofund/offckb.git"
|
|
10
10
|
},
|
|
11
11
|
"main": "dist/cli.js",
|
|
12
12
|
"bin": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function syncConfig(): void;
|