#light #ckb #ckb-cli #client #cli

应用 ckb-cli-light-client

ckb 轻客户端命令行界面

1 个不稳定版本

0.1.0 2022 年 11 月 8 日

#89#ckb

MIT 许可证

45KB
898

轻客户端命令行工具

所有子命令

$ ckb-cli-light-client --help
Usage: ckb-cli-light-client [OPTIONS] <COMMAND>

Commands:
  get-capacity        Get capacity of an address
  transfer            Transfer some capacity from given address to a receiver address
  dao                 Nervos DAO operations
  example-search-key  Output the example `SearchKey` value
  rpc                 Send jsonrpc call the ckb-light-client rpc server
  help                Print this message or the help of the given subcommand(s)

Options:
      --rpc <URL>  CKB light client rpc url [default: http://127.0.0.1:9000]
      --debug      Debug mode, print more information

教程

准备教程

首先,你需要启动一个 ckb-light-client 程序。默认 RPC 地址是 http://127.0.0.1:9000

如果你想使用 ckb-cli 的密钥,可以使用以下命令创建一个账户

$ ckb-cli account new
Your new account is locked with a password. Please give a password. Do not forget this password.
Password:
Repeat password:
address:
  mainnet: ckb1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt48tu9kdhtu6qa3rxyvth38ttmyk7ds7cg3e9w7
  testnet: ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt48tu9kdhtu6qa3rxyvth38ttmyk7ds7cxrj2yx
address(deprecated):
  mainnet: ckb1qyq82whctvmwhe5pmzxvgch0zwkhkfdumpasqdhlw4
  testnet: ckt1qyq82whctvmwhe5pmzxvgch0zwkhkfdumpasagfqzf
lock_arg: 0x753af85b36ebe681d88cc462ef13ad7b25bcd87b
lock_hash: 0xb82e384482c41f010bc5decca782e8e8c6ad41bbcdac4187659fcb937526ab1e

假设 ckb-light-client 连接到 CKB testnet,因此地址 ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt48tu9kdhtu6qa3rxyvth38ttmyk7ds7cxrj2yx 将被使用。

然后我们需要从这个地址向其他地址转移一些 CKB,或者从 测试网龙头 获取一些 CKB。

最后,我们通过 ckb-cli-light-client 安装程序(你可能需要先安装 rust 工具链)来安装 cargo install

$ cargo install --git https://github.com/TheWaWaR/ckb-cli-light-client.git --locked

转移 CKB 容量

首先,我们查询该地址的容量

$ ckb-cli-light-client get-capacity --address ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt48tu9kdhtu6qa3rxyvth38ttmyk7ds7cxrj2yx
Error: address not registered, you may use `rpc set-scripts` subcommand to register the address

它表示该地址尚未注册,我们使用 rpc set-scripts 来注册它,这样 ckb-light-client 就可以索引所有由该地址拥有的单元格

$ ckb-cli-light-client rpc set-scripts --scripts ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt48tu9kdhtu6qa3rxyvth38ttmyk7ds7cxrj2yx,1000

然后我们再次查询容量

$ ckb-cli-light-client get-capacity --address ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt48tu9kdhtu6qa3rxyvth38ttmyk7ds7cxrj2yx
synchronized number: 7085789
tip number: 7085789
tip hash: 0x7777777777777777777777777777777777777777777777777777777777777777
capacity: 50000.0 CKB

然后,我们最好阅读 transfer 子命令的帮助信息

$ ckb-cli-light-client transfer --help
Transfer some capacity from given address to a receiver address

Usage: light-client transfer [OPTIONS] --to-address <ADDR> --capacity <CAPACITY> <--from-address <ADDR>|--from-key <PRIVKEY>>

Options:
      --from-address <ADDR>    The sender address (sighash only, also be used to match key in ckb-cli keystore)
      --from-key <PRIVKEY>     The sender private key (hex string, also be used to generate sighash address)
      --to-address <ADDR>      The receiver address
      --capacity <CAPACITY>    The capacity to transfer (unit: CKB, example: 102.43)
      --skip-check-to-address  Skip check <to-address> (default only allow sighash/multisig address), be cautious to use this flag

ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt48tu9kdhtu6qa3rxyvth38ttmyk7ds7cxrj2yx 向一个地址转移一些 CKB

$ ckb-cli-light-client transfer \
    --from-address ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt48tu9kdhtu6qa3rxyvth38ttmyk7ds7cxrj2yx \
    --to-address ckt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqgaqanf \
    --capcity 200.0

在上面的示例中,ckb-cli-light-client 将通过地址 (ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt48tu9kdhtu6qa3rxyvth38ttmyk7ds7cxrj2yx) 在 ckb-cli keystore 目录中搜索,并使用密钥签署交易。该 keystore 目录通常位于 ~/.ckb-cli/keystore$CKB_CLI_HOME/keystore,如果你使用环境变量指定 ckb-cli 主目录。

然后我们再次查询该地址的容量

$ ckb-cli-light-client get-capacity --address ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt48tu9kdhtu6qa3rxyvth38ttmyk7ds7cxrj2yx
synchronized number: 7085789
tip number: 7085789
tip hash: 0x8888888888888888888888888888888888888888888888888888888888888888
capacity: 49799.99996544 CKB

依赖关系

~31–48MB
~686K SLoC