-
Notifications
You must be signed in to change notification settings - Fork 36
Tutorials
ckb-cli
is included in ckb releases, you can download ckb-cli
from ckb
release page.
If you only want ckb-cli
binary, you can download ckb-cli
from ckb-cli
release page.
If you want the latest version, you can install from source code:
git clone https://github.com/nervosnetwork/ckb-cli.git
cd ckb-cli
cargo install -f --path .
CKB use secp256k1 signature algorithm for default lock script. ckb-cli also support HD wallet (see bip32), so an extra chain code is stored. ckb-cli store the key as Web3 keystore format. Use ckb-cli account new
to create such a keystore.
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: ckb1qyqrq6m2spk7rz8mksz70dp92lcmnrre03dsaxhjnt
testnet: ckt1qyqrq6m2spk7rz8mksz70dp92lcmnrre03dsqrfdlh
lock_arg: 0x306b6a806de188fbb405e7b42557f1b98c797c5b
lock_hash: 0x4ae174831f903f5ae138ae6e25c07fc189df30c61761a78e6baa59fb57080b7a
The keystore file created at ~/.ckb-cli/keystore/UTC--2019-12-23T03-27-06.299457000Z--306b6a806de188fbb405e7b42557f1b98c797c5b
Because ckb-cli
need to sync with ckb
node for building index. We need enter into interactive mode to syncing, just type ckb-cli
enter interactive mode.
$ ckb-cli
_ _ ______ _____ __ __ ____ _____
| \ | | | ____| | __ \ \ \ / / / __ \ / ____|
| \| | | |__ | |__) | \ \ / / | | | | | (___
| . ` | | __| | _ / \ \/ / | | | | \___ \
| |\ | | |____ | | \ \ \ / | |__| | ____) |
|_| \_| |______| |_| \_\ \/ \____/ |_____/
[ ckb-cli version ]: 0.26.0 (36954d6 2019-12-18)
[ url ]: http://localhost:8114 (network: Mainnet)
[ pwd ]: ~/ckb-cli
[ color ]: true
[ debug ]: false
[ output format ]: yaml
[ completion style ]: List
[ edit style ]: Emacs
[ index db state ]: Waiting for first query
And query the syncing process by info
sub-command:
CKB> info
[ ckb-cli version ]: 0.26.0 (36954d6 2019-12-18)
[ url ]: http://localhost:8114 (network: Mainnet)
[ pwd ]: ~/ckb-cli
[ color ]: true
[ debug ]: false
[ output format ]: yaml
[ completion style ]: List
[ edit style ]: Emacs
[ index db state ]: Processed block#333186 (synced)
If it's ready ([ index db state ]: Processd block#n(synced)
), you can query address capacity by address.
CKB> wallet get-capacity --address ckb1qyqrq6m2spk7rz8mksz70dp92lcmnrre03dsaxhjnt
total: 0.0 (CKB)
Use wallet transfer
to transfer capacity from one address to another. If you want to know full functionalities of this sub-command, just type wallet transfer --help
.
CKB> wallet transfer --from-account ckt1qyqd5eyygtdmwdr7ge736zw6z0ju6wsw7rssu8fcve --to-address ckt1qyqrq6m2spk7rz8mksz70dp92lcmnrre03dsqrfdlh --capacity 20000 --max-tx-fee 0.00001
Password:
0xe0cd7f097c4e7143a3ba0780fbe6ede5ac2b2a063b1ff23d886632662fdfe259
Then you need to want this transaction been committed. If you want query the status of this transaction:
CKB> rpc get_transaction --hash 0xe0cd7f097c4e7143a3ba0780fbe6ede5ac2b2a063b1ff23d886632662fdfe259
transaction:
version: 0
cell_deps:
...
hash: 0xe0cd7f097c4e7143a3ba0780fbe6ede5ac2b2a063b1ff23d886632662fdfe259
tx_status:
status: committed
block_hash: 0xa25d36c7883c3eef0628e5d28713ae701f1d5306fe1cb674100b7681df6d2038
It says committed
, then you can query the capacity of target address to make sure transfer successed.
CKB> wallet get-capacity --address ckt1qyqrq6m2spk7rz8mksz70dp92lcmnrre03dsqrfdlh
total: 20000.0 (CKB)
There are many cells issued from genesis block locked by a period of time. For example address ckb1qyq8phsu3z4pvsdkd8xrcq9hea86ahjxadgs6xgtrv
has a cell with 5600000 will unlock until 2020-05-01
the corresponding locked address is ckb1q3w9q60tppt7l3j7r09qcp7lxnp3vcanvgha8pmvsa3jplykxn323cm0x48jcmcyd4vp6ww8nga7zew8dg2r06qrqzzqxzq8yq9ygd6z
CKB> wallet get-capacity --address ckb1q3w9q60tppt7l3j7r09qcp7lxnp3vcanvgha8pmvsa3jplykxn323cm0x48jcmcyd4vp6ww8nga7zew8dg2r06qrqzzqxzq8yq9ygd6z
total: 5600000.0 (CKB)
If you want to know the locked address of corresponding source address and an unlock date, you can use util to-genesis-multisig-addr
:
CKB> util to-genesis-multisig-addr --sighash-address ckb1qyq8phsu3z4pvsdkd8xrcq9hea86ahjxadgs6xgtrv --locktime 2020-05-01
"ckb1qyq8phsu3z4pvsdkd8xrcq9hea86ahjxadgs6xgtrv,2020-05-01,ckb1q3w9q60tppt7l3j7r09qcp7lxnp3vcanvgha8pmvsa3jplykxn323cm0x48jcmcyd4vp6ww8nga7zew8dg2r06qrqzzqxzq8yq9ygd6z"
Please note that 2020-05-01
is not precise, you can see some information about this locked address in explorer. It says 1000(th) Epoch (Estimated 2020-5-3 16:48)
, here the epoch number 1000 is a precise value, and the unlock time is about 2020-5-3.
Now if 1000(th) epoch reached, you can transfer capacity from this locked address. Since I don't have the key of address ckb1qyq8phsu3z4pvsdkd8xrcq9hea86ahjxadgs6xgtrv
, here we make an locked address in testnet for demonstration. Because the locked address rule is a little different from genesis cells, so we use util to-multisig-addr
sub-command:
CKB> util to-multisig-addr --sighash-address ckt1qyqrq6m2spk7rz8mksz70dp92lcmnrre03dsqrfdlh --locktime "2019-12-20T21:00:00+08:00"
address:
mainnet: ckb1q3w9q60tppt7l3j7r09qcp7lxnp3vcanvgha8pmvsa3jplykxn32szaa7f7d4u074m5tfa8jvz098ud8jsdv09qqqzlsgzq8yq0lsuhd
testnet: ckt1q3w9q60tppt7l3j7r09qcp7lxnp3vcanvgha8pmvsa3jplykxn32szaa7f7d4u074m5tfa8jvz098ud8jsdv09qqqzlsgzq8yqqq39na
target_epoch: "Epoch { number: 148, index: 1215, length: 1800 }"
Then we transfer some capacity to this time locked address.
CKB> wallet transfer --from-account ckt1qyqrq6m2spk7rz8mksz70dp92lcmnrre03dsqrfdlh --to-address ckt1q3w9q60tppt7l3j7r09qcp7lxnp3vcanvgha8pmvsa3jplykxn32szaa7f7d4u074m5tfa8jvz098ud8jsdv09qqqzlsgzq8yqqq39na --capacity 6000 --max-tx-fee 0.00001
Password:
0xc0aea48a815bfde35c373404e3ab757c6cfbe85b89f46f1948c3134b7a92e3f1
Query the capacity of this time locked address.
CKB> wallet get-capacity --address ckt1q3w9q60tppt7l3j7r09qcp7lxnp3vcanvgha8pmvsa3jplykxn32szaa7f7d4u074m5tfa8jvz098ud8jsdv09qqqzlsgzq8yqqq39na
total: 6000.0 (CKB)
Since "2019-12-20T21:00:00+08:00"
is a past time, we can transfer from this time locked address now.
CKB> wallet transfer --from-account ckt1qyqrq6m2spk7rz8mksz70dp92lcmnrre03dsqrfdlh --from-locked-address ckt1q3w9q60tppt7l3j7r09qcp7lxnp3vcanvgha8pmvsa3jplykxn32szaa7f7d4u074m5tfa8jvz098ud8jsdv09qqqzlsgzq8yqqq39na --to-address ckt1qyqfl02ldufnnvru7vgfzexhglf83xylmhkqfvh7l8 --capacity 5999.9999 --max-tx-fee 0.0001
Password:
0x4dddd6fc50396a3a67bad0da7442640a261a6b6a2d0ca6becb666e21bf7fc778
Here the from-acount
argument is corresponding normal address of the time locked address.
Query the target address to make sure transfer success.
CKB> wallet get-capacity --address ckt1qyqfl02ldufnnvru7vgfzexhglf83xylmhkqfvh7l8
total: 5999.9999 (CKB)