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.
- Command
- Response
offckb accounts
#### ALL ACCOUNTS ARE FOR TEST AND DEVELOP ONLY ####
#### DON'T USE THESE ACCOUNTS ON MAINNET ####
#### OTHERWISE YOU WILL LOOSE YOUR MONEY ####
Print account list, each account is funded with 42_000_000_00000000 capacity in the devnet genesis block.
- "#": 0
address: ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqvwg2cen8extgq8s5puft8vf40px3f599cytcyd8
privkey: 0x6109170b275a09ad54877b82f7d9930f88cab5717d484fb4741ae9d1dd078cd6
pubkey: 0x02025fa7b61b2365aa459807b84df065f1949d58c0ae590ff22dd2595157bffefa
lock_arg: 0x8e42b1999f265a0078503c4acec4d5e134534297
lockScript:
codeHash: 0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8
hashType: type
args: 0x8e42b1999f265a0078503c4acec4d5e134534297
- "#": 1
address: ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt435c3epyrupszm7khk6weq5lrlyt52lg48ucew
privkey: 0x9f315d5a9618a39fdc487c7a67a8581d40b045bd7a42d83648ca80ef3b2cb4a1
pubkey: 0x026efa0579f09cc7c1129b78544f70098c90b2ab155c10746316f945829c034a2d
lock_arg: 0x758d311c8483e0602dfad7b69d9053e3f917457d
lockScript:
codeHash: 0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8
hashType: type
args: 0x758d311c8483e0602dfad7b69d9053e3f917457d
- "#": 2
address: ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqvarm0tahu0qfkq6ktuf3wd8azaas0h24c9myfz6
privkey: 0x59ddda57ba06d6e9c5fa9040bdb98b4b098c2fce6520d39f51bc5e825364697a
pubkey: 0x02f1ec8d18e8ff13ecf7b3ab8f683d0c3a6d63478a7f7d14ca0fdfe8fea331e863
lock_arg: 0x9d1edebedf8f026c0d597c4c5cd3f45dec1f7557
lockScript:
codeHash: 0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8
hashType: type
args: 0x9d1edebedf8f026c0d597c4c5cd3f45dec1f7557
- "#": 3
address: ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsq0xt7prh3dy3gu9z45svp89q0d6f6c46cg9dp9mn
privkey: 0xf4a1fc19468b51ba9d1f0f5441fa3f4d91e625b2af105e1e37cc54bf9b19c0a1
pubkey: 0x02e72cbdff20422a3886ec667a138a59478d93da072173be4344c55582acdce67c
lock_arg: 0xe65f823bc5a48a38515690604e503dba4eb15d61
lockScript:
codeHash: 0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8
hashType: type
args: 0xe65f823bc5a48a38515690604e503dba4eb15d61
# More accounts...
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:
1 CKByte = 100,000,000 Shannons
- Command
- Response
offckb deposit --network devnet <your-ckb-address> <deposit-amount-in-shannon>
tx hash: 0xe895970e9c75a5c4703c38a4e37b000895e7690552ba67ef82ae92109d7322fd
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:
- Command
- Response
offckb balance <CKB-address> --network <devnet/testnet>
Balance: 42000000 CKB