Skip to content

Commit b52af5a

Browse files
authored
Merge pull request #310 from ckb-devrel/develop
Merge 0.4.1 into master
2 parents e135402 + fadad1a commit b52af5a

8 files changed

Lines changed: 290 additions & 262 deletions

File tree

README.md

Lines changed: 107 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CKB local development network for your first try.
1212
- Pre-funded test accounts
1313
- Built-in scripts like [CKB-JS-VM](https://github.com/nervosnetwork/ckb-js-vm) and [Spore-contract](https://github.com/sporeprotocol/spore-contract)
1414
- Create boilerplate to build CKB Smart Contract in Typescript
15+
- Proxy RPC that automatically dumps failed transactions for easier debugging
1516

1617
**Migrate from v0.3.x to v0.4.x:**
1718

@@ -23,12 +24,12 @@ There are BREAKING CHANGES between v0.3.x and v0.4.x, make sure to read the [mig
2324
- [Install](#install)
2425
- [Usage](#usage)
2526
- [Get started](#get-started)
26-
- [Running CKB](#running-ckb)
27-
- [List scripts info](#list-scripts-info)
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)
2832
- [Tweak Devnet Config](#tweak-devnet-config)
29-
- [Create a CKB Smart Contract Project](#create-a-ckb-smart-contract-project)
30-
- [Deploy a CKB Smart Contract](#deploy-a-ckb-smart-contract)
31-
- [Debug a transaction](#debug-a-transaction)
3233
- [Config Setting](#config-setting)
3334
- [List All Settings](#list-all-settings)
3435
- [Set CKB version](#set-ckb-version)
@@ -86,137 +87,79 @@ _Use `offckb [command] -h` to learn more about a specific command._
8687

8788
## Get started
8889

89-
### Running CKB
90-
91-
Start a local blockchain with the default CKB version:
90+
### 1. Run a Local CKB Devnet {#running-ckb}
91+
92+
Start a local blockchain with one command:
9293

9394
```sh
9495
offckb node
9596
```
9697

97-
Or specify a CKB version:
98+
Specify a CKB version:
9899

99100
```sh
100101
offckb node 0.201.0
101102
```
102103

103-
Or set the default CKB version:
104+
Or set a default version globally:
104105

105106
```sh
106107
offckb config set ckb-version 0.201.0
107108
offckb node
108109
```
110+
**RPC & Proxy RPC**
109111

110-
Once you start the devnet, there is a RPC server running at `http://127.0.0.1:8114`. There is also a RPC proxy server running at `http://127.0.0.1:28114` 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.
111-
112-
In the same way, you can also start proxy RPC server for `testnet` and `mainnet` by running:
113-
114-
```sh
115-
offckb node --network <testnet or mainnet>
116-
```
117-
118-
Using a local proxy RPC server for public testnet/mainnet is also very helpful for debugging the requests and the automatically recorded dump transactions.
119-
120-
### List scripts info
121-
122-
Print all the predefined scripts for the local blockchain:
123-
124-
```sh
125-
offckb system-scripts
126-
```
127-
128-
Or print the scripts info to a lumos JSON file:
129-
130-
```sh
131-
offckb system-scripts --export-style lumos
132-
```
112+
When the Devnet starts:
133113

134-
Or print the scripts info in a CCC style:
114+
- The RPC server runs at [http://127.0.0.1:8114](http://127.0.0.1:8114/)
115+
- The proxy RPC server runs at [http://127.0.0.1:28114](http://127.0.0.1:28114/)
135116

136-
```sh
137-
offckb system-scripts --export-style ccc
138-
```
117+
The proxy RPC server forwards all requests to the RPC server and record every requests while automatically dumping failed transactions for easier debugging.
139118

140-
You can also export the scripts info to a JSON file:
119+
You can also start a proxy RPC server for public networks:
141120

142121
```sh
143-
offckb system-scripts --output <output-file-path>
122+
offckb node --network <testnet or mainnet>
144123
```
124+
Using a proxy RPC server for Testnet/Mainnet is especially helpful for debugging transactions, since failed transactions are dumped automatically.
145125

146-
### Tweak Devnet Config
147-
148-
By default, offckb use a fixed devnet config for the local blockchain. You can tweak the config to customize the devnet, for example, modify the default log level for the devnet CKB Node `warn,ckb-script=debug`.
149-
150-
To tweak the devnet config, follow the steps below:
151-
152-
1. Locate your devnet config folder by running:
153-
154-
```sh
155-
offckb config list
156-
```
157-
158-
Result:
159-
160-
```json
161-
{
162-
"devnet": {
163-
"rpcUrl": "http://127.0.0.1:8114",
164-
"configPath": "~/Library/Application Support/offckb-nodejs/devnet",
165-
"dataPath": "~/Library/Application Support/offckb-nodejs/devnet/data"
166-
}
167-
}
168-
```
169-
170-
Pay attention to the `devnet.configPath` and `devnet.dataPath`. They are the ones we need.
171-
2. `cd` into the `devnet.configPath`, this is the config folder for the local blockchain. Modify the config in the folder to better customize the devnet. For customization, see [Custom Devnet Setup](https://docs.nervos.org/docs/node/run-devnet-node#custom-devnet-setup) and [Configure CKB](https://github.com/nervosnetwork/ckb/blob/develop/docs/configure.md) for better explanation of the config files.
172-
3. After modifications, remove everything in the `devnet.dataPath` folder. This will clean the chain data.
173-
4. Restart local blockchain by running `offckb node`
174-
175-
Done.
176-
177-
### Create a CKB Smart Contract Project
178-
179-
You can create a new CKB Smart Contract project in Typescript from our boilerplate.
180-
126+
### 2. Create a New Contract Project {#create-project}
127+
128+
Generate a ready-to-use project in JS/TS using templates:
181129
```sh
182130
offckb create <your-project-name> -c <your-contract-name>
183131
```
132+
- The `-c` option is optional, if not provided, the contract name defaults to `hello-world`.
184133

185-
The `-c` option is optional, if you don't provide it, the contract name will be `hello-world`.
186-
187-
After create the project, you can follow the instructions on build, deploy and test the contract in README.md of the project.
188-
189-
The project includes both `mock` test and `devnet` test. For developing frontend interacting with the blockchain, you can refer to the `devnet` test and see how it works.
190-
191-
### Deploy a CKB Smart Contract
192-
193-
To deploy the script, use `offckb deploy` command:
194-
134+
### 3. Deploy Your Contract {#deploy-contract}
135+
195136
```sh
196137
offckb deploy --network <devnet/testnet> --target <path-to-your-contract-binary-file-or-folder> --output <output-folder-path>
197138
```
139+
- Deployment info is written to the `output-folder-path` you specify.
198140

199-
Pass `--type-id` option if you want Scripts to be upgradable
141+
**Upgradable Scripts with `--type-id`**
142+
Pass the `--type-id` option if you want your Scripts to be upgradable:
200143

201144
```sh
202145
offckb deploy --type-id --network <devnet/testnet>
203146
```
204147

205-
Your deployed scripts info will be be listed in the `output-folder-path` which you defined in the command.
206-
207-
Note that upgrades are keyed by the contract‘s artifact name. If you plan to upgrade with `--type-id`, do not rename your contract artifact (e.g. keep `hello-world.bc`). 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.
208-
209-
### Debug a transaction
148+
- **Important**: Upgrades are keyed by the contract‘s artifact name.
149+
- If you plan to upgrade with `--type-id`, do not rename your contract artifact (e.g. keep `hello-world.bc`).
150+
- 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.
210151

211-
If you are interacting the CKB devnet via the proxy RPC server(`localhost:28114`), all the failed transactions will be dumped and recorded so you can debug them later.
212-
213-
Every time you run a transaction, you can debug it with the transaction hash:
152+
### 4. Debug Your Contract {#debug-contract}
153+
154+
When you interact with the CKB Devnet through the Proxy RPC server (localhost:28114), any failed transactions are automatically dumped and recorded for debugging.
155+
156+
**Debug a Transaction:**
214157

215158
```sh
216-
offckb debug <transaction-hash>
159+
offckb debug --tx-hash <transaction-hash> --network <devnet/testnet>
217160
```
218161

219-
It will verify all the scripts in the transaction and print the detailed info in the terminal.
162+
output example:
220163

221164
```sh
222165
offckb debug --tx-hash 0x64c936ee78107450d49e57b7453dce9031ce68b056b2f1cdad5c2218ab7232ad
@@ -243,25 +186,81 @@ Total cycles consumed: 3916670(3.7M)
243186
Transfer cycles: 43162(42.2K), running cycles: 3873508(3.7M)
244187
```
245188

246-
If you want to debug a single cell script in the transaction, you can use the following command:
189+
Debug a Single Cell Script:
247190

248191
```sh
249192
offckb debug <transaction-hash> --single-script <single-cell-script-option>
250193
```
251194

252-
The `single-cell-script-option` format is `<cell-type>[<cell-index>].<script-type>`, eg: `"input[0].lock"`
195+
The `single-cell-script-option` format is `<cell-type>[<cell-index>].<script-type>`
196+
197+
- `cell-type``input` or `output`
198+
- `cell-index` → index of the Cell in the transaction
199+
- `script-type``lock` or `type`
200+
201+
Example:
202+
203+
```sh
204+
offckb debug --tx-hash <tx-hash> --single-script input[0].lock
205+
```
206+
207+
All debug utilities are powered by [ckb-debugger](https://github.com/nervosnetwork/ckb-standalone-debugger/tree/develop/ckb-debugger).
208+
209+
### 5. Explore Built-in Scripts {#explore-scripts}
210+
211+
Print all the predefined Scripts for the local blockchain:
212+
213+
```sh
214+
offckb system-scripts --list
215+
```
216+
217+
Export options:
218+
219+
- Lumos format
220+
221+
```sh
222+
offckb system-scripts --export-style lumos
223+
```
224+
225+
- CCC format:
253226

254-
- `cell-type` could be `input` or `output`, refers to the cell type
255-
- `cell-index` is the index of the cell in the transaction
256-
- `script-type` could be `lock` or `type`, refers to the script type
227+
```sh
228+
offckb system-scripts --export-style ccc
229+
```
257230

258-
Or you can replace the script with a binary file in your single cell script debug session:
231+
- Save to a JSON file:
259232

260233
```sh
261-
offckb debug <transaction-hash> --single-script <single-cell-script-option> --bin <path/to/binary/file>
234+
offckb system-scripts --output <output-file-path>
235+
```
236+
237+
### 6. Tweak Devnet Config {#tweak-devnet-config}
238+
239+
By default, OffCKB use a fixed Devnet config. You can customize it, for example by modifying the default log level (`warn,ckb-script=debug`).
240+
241+
1. Locate your Devnet config folder:
242+
243+
```sh
244+
offckb config list
245+
```
246+
247+
Example result:
248+
249+
```json
250+
{
251+
"devnet": {
252+
"rpcUrl": "http://127.0.0.1:8114",
253+
"configPath": "~/Library/Application Support/offckb-nodejs/devnet",
254+
"dataPath": "~/Library/Application Support/offckb-nodejs/devnet/data"
255+
}
256+
}
262257
```
258+
Pay attention to the `devnet.configPath` and `devnet.dataPath`.
259+
260+
2. `cd` into the `devnet.configPath` . Modify the config files as needed. See [Custom Devnet Setup](https://docs.nervos.org/docs/node/run-devnet-node#custom-devnet-setup) and [Configure CKB](https://github.com/nervosnetwork/ckb/blob/develop/docs/configure.md) for details.
261+
3. After modifications, remove everything in the `devnet.dataPath` folder to reset chain data.
262+
4. Restart local blockchain by running `offckb node`
263263

264-
All the debug utils are borrowed from [ckb-debugger](https://github.com/nervosnetwork/ckb-standalone-debugger/tree/develop/ckb-debugger).
265264

266265
## Config Setting
267266

@@ -324,12 +323,13 @@ LOG_LEVEL=debug offckb node
324323

325324
## Accounts
326325

327-
`offckb` comes with 20 accounts, each account is funded with 42_000_000_00000000 capacity in the genesis block.
326+
OffCKB comes with 20 pre-funded accounts, each initialized with `42_000_000_00000000` capacity in the genesis block.
328327

329-
all the private keys are recorded in the `account/keys` file.
330-
detail informations about each account are recorded in the `account/account.json` file.
328+
- All private keys are stored in the `account/keys` file.
329+
- Detailed information for each account is recorded in `account/account.json`.
330+
- 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.
331331

332-
:warning: **DO NOT SEND REAL ASSETS INTO ALL THESE ACCOUNTS, YOU CAN LOOSE YOUR MONEY** :warning:
332+
:warning: **DO NOT SEND REAL ASSETS TO THESE ACCOUNTS. THE KEYS ARE PUBLIC, AND YOU MAY LOSE YOUR MONEY** :warning:
333333

334334
## About CCC
335335

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@offckb/cli",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "ckb development network for your first try",
55
"author": "CKB EcoFund",
66
"license": "MIT",

src/templates/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export const TEMPLATE_CONFIG: TemplateDependencies = {
1919
dotenv: '^17.2.1',
2020
},
2121
devDependencies: {
22-
'ckb-testtool': '~1.0.3',
23-
'@ckb-ccc/core': '~1.5.3', // Pin to version compatible with ckb-testtool
22+
'ckb-testtool': '1.0.3',
23+
'@ckb-ccc/core': '1.5.3', // lock to version compatible with ckb-testtool
2424
esbuild: '~0.25.8',
2525
jest: '~29.7.0',
2626
prettier: '^3.5.3',

templates/v3/js-script-next-js/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
"pnpm": {
1919
"onlyBuiltDependencies": [
2020
"esbuild"
21-
]
21+
],
22+
"overrides": {
23+
"brace-expansion@>=1.0.0 <=1.1.11": ">=1.1.12",
24+
"brace-expansion@>=2.0.0 <=2.0.1": ">=2.0.2",
25+
"axios@>=1.0.0 <1.12.0": ">=1.12.0",
26+
"sha.js@<=2.4.11": ">=2.4.12",
27+
"form-data@>=4.0.0 <4.0.4": ">=4.0.4"
28+
}
2229
}
2330
}

templates/v3/js-script-next-js/packages/on-chain-script/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"devDependencies": {
2424
"ckb-testtool": "~0.1.1",
25-
"esbuild": "~0.25.10"
25+
"esbuild": "~0.25.11"
2626
},
2727
"dependencies": {
2828
"@ckb-js-std/bindings": "~0.1.0",

0 commit comments

Comments
 (0)