Skip to main content

CLI Tools

Command-line tools are often used by developers to perform specific blockchain tasks in a faster and more efficient way.

CKB-CLI

ckb-cli is a CKB command-line tool developed in Rust.

If you need to interact with Mainnet blockchain from the command line, ckb-cli is an ideal choice to manage accounts, deploy Scripts and send Transactions.

Features

    rpc         Invoke RPC call to node
account Manage accounts
mock-tx Handle mock transactions (verify/send)
tx Handle common sighash/multisig transaction
util Utilities
molecule Molecule encode/decode utilities
wallet Transfer / query balance (with local index) / key utils
dao Deposit / prepare / withdraw / query NervosDAO balance (with local index) / key utils

All second-level sub-commands are listed on the wiki page.

Install

git clone https://github.com/nervosnetwork/ckb-cli.git
cd ckb-cli
cargo install --path . -f --locked

Usage

Better export an env first (or give in argument)

export API_URL=http://127.0.0.1:8114

Directly go to gorgeous interactive mode:

ckb-cli

Show available commands

# Top level help doc
ckb-cli --help
# RPC help doc
ckb-cli rpc --help

Example: Get Live Cell (JSON Output Format)

ckb-cli rpc get_live_cell --tx-hash 0x4ec75b5a8de8d180853d5046760a99285c73283a5dc528f81d6ee056f5335172 --index 0

Response:

{
"cell": {
"capacity": "125000000000",
"lock": {
"args": ["0x64257f00b6b63e987609fa9be2d0c86d351020fb"],
"code_hash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2",
"hash_type": "type"
},
"type": null
},
"status": "live"
}

OffCKB

offckb is a CLI tool developed in Node.js to help you quickly set up a predefined CKB Devnet and create dApp boilerplates.

If you need a local development environment for the very first try on your dApp, offckb is the ideal choice.

Install

npm install -g @offckb/cli

Usage

Usage: offckb [options] [command]

ckb development network for your first try

Options:
-V, --version output the version number
-h, --help display help for command

Commands:
create [your-project-name] Create a new dApp from bare templates
node Use the CKB to start devnet
clean Clean the devnet data, need to stop running the chain first
accounts Print account list info
list-hashes Use the CKB to list blockchain scripts hashes
inject-config Add offckb.config.ts to your workspace
sync-config sync offckb.config.ts in your workspace
deposit [options] [toAddress] [amountInShannon] Deposit CKB tokens to address, only devnet and testnet
transfer [options] [toAddress] [amountInShannon] Transfer 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
deployed-scripts [options] Show deployed contracts info on networks, only supports devnet and testnet
help [command] display help for command

Create a Full-Stack Project

Create a new project from predefined boilerplates.

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

The boilerplate can target on different CKB networks. Check the README.md in the project to get started.

Access Testing Accounts

offckb provides 20 pre-funded accounts for use on Devnet. Each account is funded with 42,000,000,000,000,000 capacity in the Devnet's genesis block. You can access these accounts and copy the private keys and addresses for use when developing your dApps.

offckb accounts
note

To deposit or check balances on Devnet, ensure that you have started the offckb node. This step is not required for Testnet operations.

Deposit Funds

Occasionally, you may prefer to use your personal CKB account rather than the pre-funded accounts provided by offckb. To deposit CKB into your own account using offckb, use the command below. Replace <your-ckb-address> with your personal CKB address and <deposit-amount-in-shannon> with the specific amount you wish to deposit, expressed in shannons:

CKB vs. Shannons

1 CKByte = 100,000,000 Shannons

offckb deposit --network devnet <your-ckb-address> <deposit-amount-in-shannon>

Check Balance

To check the balance of a specific account, use the following command. Replace <CKB-address> with the address of the account you want to check, and <devnet/testnet> with the appropriate network depending on which one you are using:

offckb balance <CKB-address> --network <devnet/testnet>