Nervos 挖矿第二季(教程)- Mac+Docker
基于最新的教程 https://docs.nervos.org/ 完成了,最新的挖矿测试。
优势:更简单的钱包地址生成方式。
- 流程:
1:安装CKB
2: 创建钱包
3: 用Docker运行一个CKB节点并挖矿
4: CKB浏览器查看
安装CKB
为了开始你的CKB之旅,你首先要创建一个自己的CKB钱包。
安装最新版本的CKB-CLI从GitHub releases获取。
Mac:
wget http://ckbbin.engpro.cryptape.com/ckb-cli-v0.1.2-apple-drawin.tar.gz
解压文件,并添加到自己的系统路径中
tar -xzvf ckb-cli-v0.1.2-apple-drawin.tar.gz &&
sudo ln -snf “$(pwd)/ckb-cli” /usr/local/bin/ckb-cli
你已经成功的安装了CKB-CLI,可以通过下面的命令来检查是否已经工作。
ckb-cli --version
结果:
$ ckb-cli --version
ckb-cli 0.1.2 ( 2019-05-29)
创建钱包
可以通过下面的命令创建私钥以及钱包地址等信息
ckb-cli wallet generate-key --privkey-path privkey
- 结果
$ ckb-cli wallet generate-key --privkey-path privkey
Put this config in < ckb.toml >:
[block_assembler]
code_hash = “0x9e3b3557f11b2b3532ce352bfe8017e9fd11d154c4c7f9b7aaaa1e621b539a08”
args = [“0x23a51c47aeb69ff2b702ad6efb2f01a66a1d8d30”]
{
“address”: “ckt1q9gry5zgywj3c3awk60l9dcz44h0ktcp5e4pmrfsu32mqm”,
“lock_hash”: “0xba4bf3b3bf219d219b763144bc49994a909cfdf51c7b7f3f255be79bdd12a160”,
“pubkey”: “03bea4a9f9dda6b91dc9299c6b5a2b5dac1335d460ac466a7b00b45b2da3119c71”
}
在输出的信息中,你将看到以下信息:
- [block_assembler] 是配置挖矿所必须的内容,所以一定要保留好。
- address 即钱包的地址
- lock_hash 用于解锁Cells
- pubkey 是钱包的公钥
这个命令将创建一个privkey文件,在你的当前文件夹下,在这个文件中你能找到你的私钥和地址。
$ ls
ckb-cli ckb-cli-v0.1.2-apple-drawin.tar.gz privkey
- 结果
bb0bca48d837fc44ad39c0f3afc9e857e528bf83dedb5e2b63747d3e3668a847
ckt1q9gry5zgywj3c3awk60l9dcz44h0ktcp5e4pmrfsu32mqm
用Docker运行CKB节点
参考:https://github.com/nervosnetwork/ckb/blob/develop/docs/run-ckb-with-docker.md 15
- 1:获取最新的nervos/ckb镜像
docker pull nervos/ckb:latest
注:执行以上的命令会下载最新的CKB的Docker镜像文件
$ docker pull nervos/ckb:latest
latest: Pulling from nervos/ckb
6abc03819f3e: Pull complete
05731e63f211: Pull complete
0bd67c50d6be: Pull complete
5cbe4f2000c3: Pull complete
afe9fb9c8420: Pull complete
ca28b939363c: Pull complete
c70ab9350a06: Pull complete
Digest: sha256:1783c323c88217c1b73925b603a204f9ecac7bd31ca459154c1d3a86bc603dd9
Status: Downloaded newer image for nervos/ckb:latest
- 2:配置文件挂载
参考: https://www.jianshu.com/p/8c22cdfc0ffd 5
注: 配置文件指定挖矿所用的账号(实际为args)
推荐使用挂载一个volume,在容器中的/var/lib/ckb 位置,下边的例子实现了一个挂载,并在volume生成了配置文件,可以通过它启动CKB。
- 2.1 创建一个volume
docker volume create ckb-testnet
$ docker volume create ckb-testnet
ckb-testnet
- 2.2 使用testnet chain spec 初始化目录
docker run --rm -it -v ckb-testnet:/var/lib/ckb nervos/ckb:latest init --spec testnet --force
$ docker run --rm -it
-v ckb-testnet:/var/lib/ckb
nervos/ckb:latest init --chain testnet --force
Reinitialized CKB directory in /var/lib/ckb
create ckb.toml
create ckb-miner.toml
- 2.3 创建一个容器ckb-testnet-node 并运行一个node
docker create -it -v ckb-testnet:/var/lib/ckb --name ckb-testnet-node nervos/ckb:latest run
docker create -it \ -v ckb-testnet:/var/lib/ckb \ --name ckb-testnet-node \ nervos/ckb:latest run 152c865912fc27194918656ca02fc70ca8ffc3e9160a447912e9e1bc9016a93d
- 2.4 从容器中复制创建的配置文件
docker cp ckb-testnet-node:/var/lib/ckb/ckb.toml .
docker cp ckb-testnet-node:/var/lib/ckb/ckb-miner.toml .
- 修改文件权限【坑】
chmod 777 ckb.toml
chmod 777 ckb-miner.toml
查看文件权限
bogon:ckb-testnet zhouhe$ ls -l
total 16
-rwxrwxrwx 1 zhouhe staff 543 Jun 3 14:47 ckb-miner.toml
-rwxrwxrwx 1 zhouhe staff 3566 Jun 3 15:46 ckb.toml
- -rwxrwxrwx 表示文件的权限
注: 如果你想挖矿,请编辑配置文件,在ckb.toml中替换[block_assember]部分。
- 创建之后的文件内容;
#Below is an example block assembler configuration section:
#[block_assembler]
#code_hash = “0x9e3b3557f11b2b3532ce352bfe8017e9fd11d154c4c7f9b7aaaa1e621b539a08”
#args = ["ckb cli blake160 "]
- 编辑之后的文件内容
#Below is an example block assembler configuration section:
#[block_assembler]
#code_hash = “0x9e3b3557f11b2b3532ce352bfe8017e9fd11d154c4c7f9b7aaaa1e621b539a08”
#args = ["ckb cli blake160 "]
###添加的内容— 来自钱包的创建
[block_assembler]
code_hash = "0x9e3b3557f11b2b3532ce352bfe8017e9fd11d154c4c7f9b7aaaa1e621b539a08"
args = [“0x23a51c47aeb69ff2b702ad6efb2f01a66a1d8d30”]
复制编辑完的配置文件到容器中:
docker cp ckb.toml ckb-testnet-node:/var/lib/ckb/
docker cp ckb-miner.toml ckb-testnet-node:/var/lib/ckb/
- 2.5 启动节点
docker start -i ckb-testnet-node
2019-06-03 07:44:50.097 +00:00 ChainService INFO chain block: 9426, hash: 0xc10536ac25b2adde138d55fcc2238b2ca5668333c7a69023c13ca1932eef8a7f, total_diff: 0x2b4060d, txs: 1
2019-06-03 07:44:50.097 +00:00 ChainService INFO chain block: 9427, hash: 0x811d299b48242fe1698531c2d647bff45c363d21e9ecf1273a48acc359d7b9ff, total_diff: 0x2b420ce, txs: 1
- 2.6 在容器中挖矿
docker exec ckb-testnet-node ckb miner
bogon:ckb-testnet zhouhe$ docker exec ckb-testnet-node ckb miner
2019-06-03 07:48:35.632 +00:00 main INFO sentry Notice: The ckb process will send stack trace to sentry on Rust panics. This is enabled by default before mainnet, which can be opted out by setting the option dsn
to empty in the config file. The DSN is now https://[email protected]/1422795
2019-06-03 07:53:30.372 +00:00 main INFO miner found seal: Seal { nonce: 829098104869847506, proof: 0x0e130000ab20000004270000e93c00003c4000008c4c0000704e0000e35a00004a670000667000004f7800004d7f0000 }