@offckb/cli 0.3.0-canary-0e33d0a.0 → 0.3.0-canary-119a74a.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 +70 -1
- package/dist/cli.js +7 -0
- package/dist/cmd/repl.d.ts +11 -0
- package/dist/cmd/repl.js +75 -0
- package/dist/template/option.js +17 -5
- package/package.json +1 -1
- package/dist/template/option.json +0 -16
package/README.md
CHANGED
|
@@ -32,6 +32,10 @@ Start building on CKB blockchain, right now, right away!
|
|
|
32
32
|
- [Start the frontend project](#start-the-frontend-project)
|
|
33
33
|
- [Debug a transaction](#debug-a-transaction)
|
|
34
34
|
- [Generate Moleculec bindings](#generate-moleculec-bindings)
|
|
35
|
+
- [REPL Mode](#repl-mode)
|
|
36
|
+
- [Start the OffCKB REPL](#start-the-offckb-repl)
|
|
37
|
+
- [Build CKB transaction in REPL](#build-ckb-transaction-in-repl)
|
|
38
|
+
- [Get balance in REPL](#get-balance-in-repl)
|
|
35
39
|
- [Config Setting](#config-setting)
|
|
36
40
|
- [List All Settings](#list-all-settings)
|
|
37
41
|
- [Set CKB version](#set-ckb-version)
|
|
@@ -48,7 +52,7 @@ Start building on CKB blockchain, right now, right away!
|
|
|
48
52
|
npm install -g @offckb/cli
|
|
49
53
|
```
|
|
50
54
|
|
|
51
|
-
_We
|
|
55
|
+
_We recommend using [LTS](https://nodejs.org/en/download/package-manager) version of Node to run `offckb`_
|
|
52
56
|
|
|
53
57
|
## Usage
|
|
54
58
|
|
|
@@ -80,6 +84,7 @@ Commands:
|
|
|
80
84
|
debug [options] CKB Debugger for development
|
|
81
85
|
system-scripts [options] Output system scripts of the local devnet
|
|
82
86
|
mol [options] Generate CKB Moleculec binding code for development
|
|
87
|
+
repl [options] A custom Nodejs REPL environment bundle for CKB.
|
|
83
88
|
help [command] display help for command
|
|
84
89
|
```
|
|
85
90
|
|
|
@@ -308,6 +313,70 @@ If you have multiple `.mol` files, you can use a folder as the input and specify
|
|
|
308
313
|
offckb mol --schema <path/to/mol/folder> --output-folder <path/to/output/folder> --lang <lang>
|
|
309
314
|
```
|
|
310
315
|
|
|
316
|
+
## REPL Mode
|
|
317
|
+
|
|
318
|
+
OffCKB pack a custom Nodejs REPL with built-in variables and functions to help you develop CKB right in the terminal with minimal effort. This is suitable for simple script testing task when you don't want to write long and serious codes.
|
|
319
|
+
|
|
320
|
+
### Start the OffCKB REPL
|
|
321
|
+
|
|
322
|
+
```sh
|
|
323
|
+
offckb repl --network <devnet/testnet/mainnet, default: devnet>
|
|
324
|
+
|
|
325
|
+
Welcome to OffCKB REPL!
|
|
326
|
+
[[ Default Network: devnet, enableProxyRPC: false ]]
|
|
327
|
+
Type 'help()' to learn how to use.
|
|
328
|
+
OffCKB >
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
Type `help()` to learn about the built-in variables and functions:
|
|
332
|
+
|
|
333
|
+
```sh
|
|
334
|
+
OffCKB > help()
|
|
335
|
+
|
|
336
|
+
OffCKB Repl, a Nodejs REPL with CKB bundles.
|
|
337
|
+
|
|
338
|
+
Global Variables to use:
|
|
339
|
+
- ccc, cccA, imported from CKB Javascript SDK CCC
|
|
340
|
+
- client, a CCC client instance bundle with current network
|
|
341
|
+
- Client, a Wrap of CCC client class, you can build new client with
|
|
342
|
+
const myClient = Client.new('devnet' | 'testnet' | 'mainnet');
|
|
343
|
+
// or
|
|
344
|
+
const myClient = Client.fromUrl('<your rpc url>', 'devnet' | 'testnet' | 'mainnet');
|
|
345
|
+
- accounts, test accounts array from OffCKB
|
|
346
|
+
- networks, network information configs
|
|
347
|
+
- help, print this help message
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### Build CKB transaction in REPL
|
|
351
|
+
|
|
352
|
+
```sh
|
|
353
|
+
OffCKB > let amountInCKB = ccc.fixedPointFrom(63);
|
|
354
|
+
OffCKB > let tx = ccc.Transaction.from({
|
|
355
|
+
... outputs: [
|
|
356
|
+
... {
|
|
357
|
+
... capacity: ccc.fixedPointFrom(amountInCKB),
|
|
358
|
+
... lock: accounts[0].lockScript,
|
|
359
|
+
... },
|
|
360
|
+
... ],
|
|
361
|
+
... });
|
|
362
|
+
OffCKB > let signer = new ccc.SignerCkbPrivateKey(client, accounts[0].privkey);
|
|
363
|
+
OffCKB > await tx.completeInputsByCapacity(signer);
|
|
364
|
+
2
|
|
365
|
+
OffCKB > await tx.completeFeeBy(signer, 1000);
|
|
366
|
+
[ 0, true ]
|
|
367
|
+
OffCKB > await mySigner.sendTransaction(tx)
|
|
368
|
+
'0x50fbfa8c47907d6842a325e85e48d5da6917e16ca7e2253ec3bd5bcdf8da99ce'
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### Get balance in REPL
|
|
372
|
+
|
|
373
|
+
```sh
|
|
374
|
+
OffCKB > let myClient = Client.fromUrl(networks.testnet.rpc_url, 'testnet');
|
|
375
|
+
OffCKB > await myClient.getBalanceSingle(accounts[0].lockScript);
|
|
376
|
+
60838485293944n
|
|
377
|
+
OffCKB >
|
|
378
|
+
```
|
|
379
|
+
|
|
311
380
|
## Config Setting
|
|
312
381
|
|
|
313
382
|
### List All Settings
|
package/dist/cli.js
CHANGED
|
@@ -54,6 +54,7 @@ const proxy_rpc_1 = require("./cmd/proxy-rpc");
|
|
|
54
54
|
const mol_1 = require("./cmd/mol");
|
|
55
55
|
const fs = __importStar(require("fs"));
|
|
56
56
|
const transfer_all_1 = require("./cmd/transfer-all");
|
|
57
|
+
const repl_1 = require("./cmd/repl");
|
|
57
58
|
const version = require('../package.json').version;
|
|
58
59
|
const description = require('../package.json').description;
|
|
59
60
|
// fix windows terminal encoding of simplified chinese text
|
|
@@ -186,6 +187,12 @@ program
|
|
|
186
187
|
}
|
|
187
188
|
return (0, mol_1.molSingleFile)(option.schema, option.output, option.lang);
|
|
188
189
|
}));
|
|
190
|
+
program
|
|
191
|
+
.command('repl')
|
|
192
|
+
.description('A custom Nodejs REPL environment bundle for CKB.')
|
|
193
|
+
.option('--network <network>', 'Specify the network to deploy to', 'devnet')
|
|
194
|
+
.option('-r, --proxy-rpc', 'Use Proxy RPC to connect to blockchain')
|
|
195
|
+
.action(repl_1.repl);
|
|
189
196
|
program.parse(process.argv);
|
|
190
197
|
// If no command is specified, display help
|
|
191
198
|
if (!process.argv.slice(2).length) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ccc } from '@ckb-ccc/core';
|
|
2
|
+
import { Network, NetworkOption } from '../type/base';
|
|
3
|
+
export interface ReplProp extends NetworkOption {
|
|
4
|
+
proxyRpc?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function repl({ network, proxyRpc }: ReplProp): void;
|
|
7
|
+
export declare function initGlobalClientBuilder(): {
|
|
8
|
+
new: (network: Network) => ccc.ClientPublicTestnet | ccc.ClientPublicMainnet;
|
|
9
|
+
fromUrl: (rpcUrl: string, network: Network) => ccc.ClientPublicTestnet | ccc.ClientPublicMainnet;
|
|
10
|
+
};
|
|
11
|
+
export declare function printHelpText(): void;
|
package/dist/cmd/repl.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.printHelpText = exports.initGlobalClientBuilder = exports.repl = void 0;
|
|
7
|
+
const repl_1 = require("repl");
|
|
8
|
+
const core_1 = require("@ckb-ccc/core");
|
|
9
|
+
const advanced_1 = require("@ckb-ccc/core/advanced");
|
|
10
|
+
const network_1 = require("../sdk/network");
|
|
11
|
+
const base_1 = require("../type/base");
|
|
12
|
+
const private_1 = require("../scripts/private");
|
|
13
|
+
const account_json_1 = __importDefault(require("../../account/account.json"));
|
|
14
|
+
const validator_1 = require("../util/validator");
|
|
15
|
+
function repl({ network = base_1.Network.devnet, proxyRpc = false }) {
|
|
16
|
+
(0, validator_1.validateNetworkOpt)(network);
|
|
17
|
+
console.log(
|
|
18
|
+
// Note remember update the CCC version since require CCC's package.json not work
|
|
19
|
+
`Welcome to OffCKB REPL!\n[[ Default Network: ${network}, enableProxyRPC: ${proxyRpc}, CCC SDK: 0.0.16-alpha.3 ]]\nType 'help()' to learn how to use.`);
|
|
20
|
+
const context = (0, repl_1.start)({
|
|
21
|
+
prompt: 'OffCKB > ',
|
|
22
|
+
ignoreUndefined: true,
|
|
23
|
+
useColors: true,
|
|
24
|
+
}).context;
|
|
25
|
+
context.ccc = core_1.ccc;
|
|
26
|
+
context.cccA = advanced_1.cccA;
|
|
27
|
+
context.networks = network_1.networks;
|
|
28
|
+
context.Client = initGlobalClientBuilder();
|
|
29
|
+
context.client = initGlobalClientBuilder().new(network);
|
|
30
|
+
context.accounts = account_json_1.default;
|
|
31
|
+
context.help = printHelpText;
|
|
32
|
+
}
|
|
33
|
+
exports.repl = repl;
|
|
34
|
+
function initGlobalClientBuilder() {
|
|
35
|
+
return {
|
|
36
|
+
new: (network) => {
|
|
37
|
+
return network === 'mainnet'
|
|
38
|
+
? new core_1.ccc.ClientPublicMainnet()
|
|
39
|
+
: network === 'testnet'
|
|
40
|
+
? new core_1.ccc.ClientPublicTestnet()
|
|
41
|
+
: new core_1.ccc.ClientPublicTestnet({
|
|
42
|
+
url: network_1.networks.devnet.rpc_url,
|
|
43
|
+
scripts: (0, private_1.buildCCCDevnetKnownScripts)(),
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
fromUrl: (rpcUrl, network) => {
|
|
47
|
+
return network === 'mainnet'
|
|
48
|
+
? new core_1.ccc.ClientPublicMainnet({ url: rpcUrl })
|
|
49
|
+
: network === 'testnet'
|
|
50
|
+
? new core_1.ccc.ClientPublicTestnet({ url: rpcUrl })
|
|
51
|
+
: new core_1.ccc.ClientPublicTestnet({
|
|
52
|
+
url: rpcUrl,
|
|
53
|
+
scripts: (0, private_1.buildCCCDevnetKnownScripts)(),
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
exports.initGlobalClientBuilder = initGlobalClientBuilder;
|
|
59
|
+
function printHelpText() {
|
|
60
|
+
return console.log(`
|
|
61
|
+
OffCKB Repl, a Nodejs REPL with CKB bundles.
|
|
62
|
+
|
|
63
|
+
Global Variables to use:
|
|
64
|
+
- ccc, cccA, imported from CKB Javascript SDK CCC
|
|
65
|
+
- client, a CCC client instance bundle with current network
|
|
66
|
+
- Client, a Wrap of CCC client class, you can build new client with
|
|
67
|
+
const myClient = Client.new('devnet' | 'testnet' | 'mainnet');
|
|
68
|
+
// or
|
|
69
|
+
const myClient = Client.fromUrl('<your rpc url>', 'devnet' | 'testnet' | 'mainnet');
|
|
70
|
+
- accounts, test accounts array from OffCKB
|
|
71
|
+
- networks, network information configs
|
|
72
|
+
- help, print this help message
|
|
73
|
+
`);
|
|
74
|
+
}
|
|
75
|
+
exports.printHelpText = printHelpText;
|
package/dist/template/option.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.loadBareTemplateOpts = void 0;
|
|
7
|
-
const
|
|
4
|
+
const templates = [
|
|
5
|
+
{
|
|
6
|
+
name: 'Remix-Vite Bare Templates',
|
|
7
|
+
value: 'remix-vite-template',
|
|
8
|
+
description: 'A full-stack template with Remix-vite and ckb-script-templates',
|
|
9
|
+
tag: ['remix', 'vite', 'tailwindcss', 'ckb-script-templates', 'typescript', 'rust'],
|
|
10
|
+
author: 'retric@cryptape.com',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'Next.js Bare Templates',
|
|
14
|
+
value: 'next-js-template',
|
|
15
|
+
description: 'A full-stack template with Next.js framework and ckb-script-templates',
|
|
16
|
+
tag: ['next.js', 'tailwindcss', 'ckb-script-templates', 'typescript', 'rust'],
|
|
17
|
+
author: 'retric@cryptape.com',
|
|
18
|
+
},
|
|
19
|
+
];
|
|
8
20
|
function loadBareTemplateOpts() {
|
|
9
|
-
return
|
|
21
|
+
return templates;
|
|
10
22
|
}
|
|
11
23
|
exports.loadBareTemplateOpts = loadBareTemplateOpts;
|
package/package.json
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"name": "Remix-Vite Bare Templates",
|
|
4
|
-
"value": "remix-vite-template",
|
|
5
|
-
"description": "A full-stack template with Remix-vite and ckb-script-templates",
|
|
6
|
-
"tag": ["remix", "vite", "tailwindcss", "ckb-script-templates", "typescript", "rust"],
|
|
7
|
-
"author": "retric@cryptape.com"
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
"name": "Next.js Bare Templates",
|
|
11
|
-
"value": "next-js-template",
|
|
12
|
-
"description": "A full-stack template with Next.js framework and ckb-script-templates",
|
|
13
|
-
"tag": ["next.js", "tailwindcss", "ckb-script-templates", "typescript", "rust"],
|
|
14
|
-
"author": "retric@cryptape.com"
|
|
15
|
-
}
|
|
16
|
-
]
|