Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 22 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ Options:
-h, --help display help for command

Commands:
node [options] [CKB-Version] Use the CKB to start devnet
create [options] [your-project-name] Create a new dApp from bare templates
node [CKB-Version] Use the CKB to start devnet
create [options] [project-name] Create a new CKB Smart Contract project in JavaScript.
deploy [options] Deploy contracts to different networks, only supports devnet and testnet
debug [options] CKB Debugger for development
system-scripts [options] Print/Output system scripts of the CKB blockchain
clean Clean the devnet data, need to stop running the chain first
accounts Print account list info
deposit [options] [toAddress] [amountInCKB] Deposit CKB tokens to address, only devnet and testnet
transfer [options] [toAddress] [amountInCKB] Transfer CKB tokens to address, only devnet and testnet
transfer-all [options] [toAddress] Transfer All CKB tokens to address, only devnet and testnet
balance [options] [toAddress] Check account balance, only devnet and testnet
deploy [options] Deploy contracts to different networks, only supports devnet and testnet
config <action> [item] [value] do a configuration action
debug [options] CKB Debugger for development
system-scripts [options] Output system scripts of the local devnet
help [command] display help for command
```

Expand All @@ -73,13 +73,13 @@ offckb node
Or specify a CKB version:

```sh
offckb node 0.117.0
offckb node 0.201.0
```

Or set the default CKB version:

```sh
offckb config set ckb-version 0.117.0
offckb config set ckb-version 0.201.0
offckb node
```

Expand Down Expand Up @@ -144,76 +144,42 @@ Pay attention to the `devnet.configPath` and `devnet.dataPath`. They are the one

Done.

### Create a full-stack Project

Create a new project from predefined boilerplates.

```sh
offckb create <your-project-name, eg:my-first-ckb-project>
```

The boilerplate can be targeting on different CKB networks. Check [README.md](https://github.com/nervosnetwork/docs.nervos.org/blob/develop/examples/remix-vite-template/readme.md) in the project to get started.

### Create a script-only Project

You can create a new script project without a frontend. This is useful when you only want to develop smart contracts for CKB.

```sh
offckb create <your-project-name> --script
```

Note: you need to have pnpm installed in your environment to use this command. offckb doesn't do anything really, it just call [create-js-vm-app](https://github.com/nervosnetwork/ckb-js-vm/tree/main/packages/create-app) to do all the magic.

### Create a dApp-only Project
### Create a CKB Smart Contract Project

You can create a new dApp project without the script(CKB Smart Contract). This is useful when you don't need to create your own on-chain script logic.
You can create a new CKB Smart Contract project in JavaScript from our boilerplate.

```sh
offckb create <your-project-name> --dapp # or -d
offckb create <your-project-name>
```

### Build and Deploy a script
### Build and Deploy a CKB Smart Contract

The fullstack boilerplate project is a monorepo, which contains a script project and a frontend project.

To build the script, in the root of the project, run:
After creating the project, you can build the CKB Smart Contract project by running:

```sh
make build
cd <your-project-name> && npm/yarn/pnpm run build
```

To deploy the script, cd into the frontend folder where the default `offckb.config.ts` file is located and run:
To deploy the script, use `offckb deploy` command:

```sh
cd frontend && offckb deploy --network <devnet/testnet>
```

Or specific the `offckb.config.ts` file path for deploy command to locate:

```sh
offckb deploy --network <devnet/testnet> --config <file-path-to-your-offckb.config.ts-file>
offckb deploy --network <devnet/testnet> --target <path-to-your-contract-binary-file-or-folder> --output <output-folder-path>
```

Pass `--type-id` option if you want Scripts to be upgradable

```sh
cd frontend && offckb deploy --type-id --network <devnet/testnet>
```

Once the deployment is done, you can use the following command to check the deployed scripts:

```sh
offckb my-scripts --network <devnet/testnet>
offckb deploy --type-id --network <devnet/testnet>
```

Your deployed scripts will be also be listed in the `frontend/offckb/my-scripts` folder in your frontend project.
Your deployed scripts will be be listed in the `output-folder-path` which you defined in the command.

### Start the frontend project
### Test CKB Smart Contract

To start the frontend project, cd into the frontend folder and run:
To test the CKB Smart Contract project, cd into the project folder and run:

```sh
npm i & npm run dev
npm/yarn/pnpm run test
```

### Debug a transaction
Expand Down Expand Up @@ -316,6 +282,8 @@ offckb config get proxy
- commit id: 410b16c
- [x] Spore https://github.com/sporeprotocol/spore-contract
- version: 0.2.2-beta.1
- [x] CKB-JS-VM https://github.com/nervosnetwork/ckb-js-vm
- version: 1.0.0

## Accounts

Expand Down
22 changes: 22 additions & 0 deletions docs/migration.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# Migration from v0.3.x to v0.4.x

## BREAKING CHANGES

1. The default log level in devnet is changed to `warn,ckb-script=debug` from `info`
2. The devnet RPC proxy sever is now default running, and proxy port is changed to `28114` from `9000`
3. The `create` command is now focusing on creating a CKB Smart Contract project in JavaScript, instead of a dApp project.
4. `offckb.config.ts` file is removed, and the `deploy` command now requires `--target` and `--output` options to specify the contract binary file or folder path and the output folder path.
5. `ckb-js-vm` is now added to built-in scripts in offckb devnet.
6. `system-scripts` command has a new option called `-o, --output` to specify the output json file path for the system scripts.
7. The build system is changed from `npm-shrinkwrap.json` to `ncc` toolchain.

## Removed commands

- `proxy-rpc`
- `mol`
- `repl`
- `list-hashes`
- `my-scripts`
- `sync-scripts`
- `inject-config`

# Migration from v0.2.x to v0.3.x

## BREAKING CHANGES
Expand Down
34 changes: 6 additions & 28 deletions src/cfg/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@

export interface Settings {
proxy?: ProxyConfig;
rpc: {
proxyPort: number;
};
bins: {
rootFolder: string;
defaultCKBVersion: string;
downloadPath: string;
};
devnet: {
rpcUrl: string;
rpcProxyPort: number;
configPath: string;
dataPath: string;
debugFullTransactionsPath: string;
Expand All @@ -44,30 +42,21 @@
};
testnet: {
rpcUrl: string;
rpcProxyPort: number;
debugFullTransactionsPath: string;
transactionsPath: string;
failedTransactionsPath: string;
contractsPath: string;
};
mainnet: {
rpcUrl: string;
rpcProxyPort: number;
debugFullTransactionsPath: string;
transactionsPath: string;
failedTransactionsPath: string;
contractsPath: string;
};
dappTemplate: {
gitRepoUrl: string;
gitBranch: string;
gitFolder: string;
downloadPath: string;
};
tools: {
moleculeES: {
downloadPath: string;
cachePath: string;
binFolder: string;
};
ckbDebugger: {
minVersion: string;
};
Expand All @@ -76,16 +65,14 @@

export const defaultSettings: Settings = {
proxy: undefined,
rpc: {
proxyPort: 28114,
},
bins: {
rootFolder: path.resolve(dataPath, 'bins'),
defaultCKBVersion: '0.201.0',
downloadPath: path.resolve(cachePath, 'download'),
},
devnet: {
rpcUrl: 'http://localhost:8114',
rpcProxyPort: 28114,
// todo: maybe add a root folder for all devnet data
// so we can clean it easily
configPath: path.resolve(dataPath, 'devnet'),
Expand All @@ -97,30 +84,21 @@
},
testnet: {
rpcUrl: 'https://testnet.ckb.dev',
rpcProxyPort: 38114,
debugFullTransactionsPath: path.resolve(dataPath, 'testnet/full-transactions'),
transactionsPath: path.resolve(dataPath, 'testnet/transactions'),
failedTransactionsPath: path.resolve(dataPath, 'testnet/failed-transactions'),
contractsPath: path.resolve(dataPath, 'testnet/contracts'),
},
mainnet: {
rpcUrl: 'https://mainnet.ckb.dev',
rpcProxyPort: 48114,
debugFullTransactionsPath: path.resolve(dataPath, 'mainnet/full-transactions'),
transactionsPath: path.resolve(dataPath, 'mainnet/transactions'),
failedTransactionsPath: path.resolve(dataPath, 'mainnet/failed-transactions'),
contractsPath: path.resolve(dataPath, 'mainnet/contracts'),
},
dappTemplate: {
gitRepoUrl: `https://github.com/ckb-devrel/offckb`,
gitBranch: 'master',
gitFolder: 'templates/v3',
downloadPath: path.resolve(cachePath, 'download', 'dapp-template'),
},
tools: {
moleculeES: {
downloadPath: path.resolve(cachePath, 'download', 'molecule-es'),
cachePath: path.resolve(cachePath, 'tools', 'moleculec-es'),
binFolder: path.resolve(dataPath, 'tools', 'moleculec-es'),
},
ckbDebugger: {
minVersion: '0.200.0',
},
Expand Down Expand Up @@ -160,7 +138,7 @@
return `${getCKBBinaryInstallPath(version)}/ckb`;
}

function deepMerge(target: any, source: any): any {

Check warning on line 141 in src/cfg/setting.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 141 in src/cfg/setting.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 141 in src/cfg/setting.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 141 in src/cfg/setting.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 141 in src/cfg/setting.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 141 in src/cfg/setting.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
for (const key in source) {
if (source[key] && typeof source[key] === 'object') {
if (!target[key]) {
Expand Down
100 changes: 50 additions & 50 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ setUTF8EncodingForWindows();
const program = new Command();
program.name('offckb').description(description).version(version);

program
.command('node [CKB-Version]')
.description('Use the CKB to start devnet')
.action(async (version: string) => {
return node({ version });
});

program
.command('create [project-name]')
.description('Create a new CKB Smart Contract project in JavaScript.')
Expand All @@ -37,10 +44,49 @@ program
});

program
.command('node [CKB-Version]')
.description('Use the CKB to start devnet')
.action(async (version: string) => {
return node({ version });
.command('deploy')
.description('Deploy contracts to different networks, only supports devnet and testnet')
.option('--network <network>', 'Specify the network to deploy to', 'devnet')
.option('--target <target>', 'Specify the script binaries file/folder path to deploy', './')
.option('-o, --output <output>', 'Specify the output folder path for the deployment record files', './deployment')
.option('-t, --type-id', 'Specify if use upgradable type id to deploy the script')
.option('--privkey <privkey>', 'Specify the private key to deploy scripts')
.action((options: DeployOptions) => deploy(options));

program
.command('debug')
.requiredOption('--tx-hash <txHash>', 'Specify the transaction hash to debug with')
.option('--single-script <singleScript>', 'Specify the cell script to debug with')
.option('--bin <bin>', 'Specify a binary to replace the script to debug with')
.option('--network <network>', 'Specify the network to debug', 'devnet')
.description('CKB Debugger for development')
.action(async (option) => {
const txHash = option.txHash;
if (option.singleScript) {
const { cellType, cellIndex, scriptType } = parseSingleScriptOption(option.singleScript);
return debugSingleScript(txHash, cellIndex, cellType, scriptType, option.network, option.bin);
}
return debugTransaction(txHash, option.network);
});

program
.command('system-scripts')
.option('--export-style <exportStyle>', 'Specify the export format, possible values are system, lumos and ccc.')
.option('--network <network>', 'Specify the CKB blockchain network', 'devnet')
.option(
'-o, --output <output>',
'Specify the output json file path for the system scripts, export-style and network will be ignored if output is specified',
)
.description('Print/Output system scripts of the CKB blockchain')
.action(async (option) => {
const network = option.network;
const exportStyle = option.exportStyle;
if (option.output) {
await genSystemScriptsJsonFile(option.output);
console.log(`File ${option.output} generated successfully.`);
return;
}
return printSystemScripts({ style: exportStyle, network });
});

program.command('clean').description('Clean the devnet data, need to stop running the chain first').action(clean);
Expand Down Expand Up @@ -83,57 +129,11 @@ program
return balanceOf(toAddress, options);
});

program
.command('deploy')
.description('Deploy contracts to different networks, only supports devnet and testnet')
.option('--network <network>', 'Specify the network to deploy to', 'devnet')
.option('--target <target>', 'Specify the script binaries file/folder path to deploy', './')
.option('-o, --output <output>', 'Specify the output folder path for the deployment record files', './deployment')
.option('-t, --type-id', 'Specify if use upgradable type id to deploy the script')
.option('--privkey <privkey>', 'Specify the private key to deploy scripts')
.action((options: DeployOptions) => deploy(options));

program
.command('config <action> [item] [value]')
.description('do a configuration action')
.action((action, item, value) => Config(action, item as ConfigItem, value));

program
.command('debug')
.requiredOption('--tx-hash <txHash>', 'Specify the transaction hash to debug with')
.option('--single-script <singleScript>', 'Specify the cell script to debug with')
.option('--bin <bin>', 'Specify a binary to replace the script to debug with')
.option('--network <network>', 'Specify the network to debug', 'devnet')
.description('CKB Debugger for development')
.action(async (option) => {
const txHash = option.txHash;
if (option.singleScript) {
const { cellType, cellIndex, scriptType } = parseSingleScriptOption(option.singleScript);
return debugSingleScript(txHash, cellIndex, cellType, scriptType, option.network, option.bin);
}
return debugTransaction(txHash, option.network);
});

program
.command('system-scripts')
.option('--export-style <exportStyle>', 'Specify the export format, possible values are system, lumos and ccc.')
.option('--network <network>', 'Specify the CKB blockchain network', 'devnet')
.option(
'-o, --output <output>',
'Specify the output json file path for the system scripts, export-style and network will be ignored if output is specified',
)
.description('Print/Output system scripts of the CKB blockchain')
.action(async (option) => {
const network = option.network;
const exportStyle = option.exportStyle;
if (option.output) {
await genSystemScriptsJsonFile(option.output);
console.log(`File ${option.output} generated successfully.`);
return;
}
return printSystemScripts({ style: exportStyle, network });
});

program.parse(process.argv);

// If no command is specified, display help
Expand Down
Loading