本搭建过程根据官网教程(https://developers.eos.io/eosio-home/docs/setting-up-your-environment)进行,主要步骤如下:

一、安装docker

1、Debian 9安装docker ce(过程参照),docker官网的下载需要注册帐号才能下载,未尝试。

二、新建开发目录

shell

$mkdir contracts

$cd contracts

$pwd

结果 /home/game/contracts 向教程网页提交此绝对路径,以便自动生成后续使用代码中的路径。

三、EOS节点安装

1、获得EOS的docker镜像 

$ docker pull eosio/eos:v1.4.2

2、启动节点和钱包

shell(注命令中已包含上面的绝对路径)

docker run --name eosio \
  --publish 7777:7777 \
  --publish 127.0.0.1:5555:5555 \
  --volume /home/game/contracts:/home/game/contracts \
  --detach \
  eosio/eos:v1.4.2 \
  /bin/bash -c \
  "keosd --http-server-address=0.0.0.0:5555 & exec nodeos -e -p eosio --plugin eosio::producer_plugin --plugin eosio::chain_api_plugin --plugin eosio::history_plugin --plugin eosio::history_api_plugin --plugin eosio::http_plugin -d /mnt/dev/data --config-dir /mnt/dev/config --http-server-address=0.0.0.0:7777 --access-control-allow-origin=* --contracts-console --http-validate-host=false --filter-on='*'"

3、检查安装是否正确

3.1确定节点可产生区块

shell

docker logs --tail 10 eosio

正确结果应该类似如下:

1929001ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 0000366974ce4e2a... #13929 @ 2018-05-23T16:32:09.000 signed by eosio [trxs: 0, lib: 13928, confirmed: 0]
 1929502ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 0000366aea085023... #13930 @ 2018-05-23T16:32:09.500 signed by eosio [trxs: 0, lib: 13929, confirmed: 0]
 1930002ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 0000366b7f074fdd... #13931 @ 2018-05-23T16:32:10.000 signed by eosio [trxs: 0, lib: 13930, confirmed: 0]
 1930501ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 0000366cd8222adb... #13932 @ 2018-05-23T16:32:10.500 signed by eosio [trxs: 0, lib: 13931, confirmed: 0]
 1931002ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 0000366d5c1ec38d... #13933 @ 2018-05-23T16:32:11.000 signed by eosio [trxs: 0, lib: 13932, confirmed: 0]
 1931501ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 0000366e45c1f235... #13934 @ 2018-05-23T16:32:11.500 signed by eosio [trxs: 0, lib: 13933, confirmed: 0]
 1932001ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 0000366f98adb324... #13935 @ 2018-05-23T16:32:12.000 signed by eosio [trxs: 0, lib: 13934, confirmed: 0]
 1932501ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 00003670a0f01daa... #13936 @ 2018-05-23T16:32:12.500 signed by eosio [trxs: 0, lib: 13935, confirmed: 0]
 1933001ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 00003671e8b36e1e... #13937 @ 2018-05-23T16:32:13.000 signed by eosio [trxs: 0, lib: 13936, confirmed: 0]
 1933501ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 0000367257fe1623... #13938 @ 2018-05-23T16:32:13.500 signed by eosio [trxs: 0, lib: 13937, confirmed: 0]

3.2检查钱包

docker exec -it eosio bash

进入eosio命令行之后,输入:

cleos --wallet-url http://127.0.0.1:5555 wallet list keys

正确结果应为:

Wallets:
[]

退出eosio命令行

exit

3.3检查节点终端

1、网页打开http://localhost:7777/v1/chain/get_info

2、控制台shell命令:

curl http://localhost:7777/v1/chain/get_info

1、2返回的结果内容应该一致,是一个json格式字符串内容。

4、命令别名化cleos

shell

alias cleos='docker exec -it eosio /opt/eosio/bin/cleos --url http://127.0.0.1:7777 --wallet-url http://127.0.0.1:5555'

临时别名直接在控制台运行,如要配置成环境直接生效则需添加进你 的.bash_rc文件

5、其他EOS的docker运行命令:

Start/Stop Container

docker start eosio
docker stop eosio

打开EOS的Bash

docker exec -it eosio bash

Remove the EOSIO Container

docker rm eosio

四、安装EOS合约开发包

debian、ubuntu环境下:

Install   Shell

wget https://github.com/eosio/eosio.cdt/releases/download/v1.3.2/eosio.cdt-1.3.2.x86_64.deb
sudo apt install ./eosio.cdt-1.3.2.x86_64.deb

Uninstall  Shell

sudo apt remove eosio.cdt

 

另外也可以从源码安装,此方式未尝试,有空再试。

五、理解EOS架构

docker 磁盘io高 docker ce io_bash

nodeos (node + eos = nodeos):节点

cleos (cli + eos = cleos) :命令行终端

keosd (key + eos = keosd) :钱包管理相关

eosio-cpp :eosio.cdt的功能之一,将 C++代码编译成 WASM文件,并生成ABIs。个人理解为类似于QT的qmake功能。

六、创建开发钱包

1、创建默认钱包

cleos wallet create --to-console

开发环境--to-console选项没有太多安全隐患,生产环境应该使用--to-file。

cleos返回

Creating wallet: default
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5Kewn9L76X8Fpd....................t42S9XCw2"

需注意密码保存好,以便后续继续使用。

2、打开钱包

cleos wallet open
cleos wallet list

将返回:

Wallets:
[
  "default"
]

3、解锁钱包

cleos wallet unlock
cleos wallet list

将返回(注有 *):

Wallets:
[
  "default *"
]

4、钱包导入keys

cleos wallet create_key

返回类似如下:

Created new private key with a public key of: "EOS8PEJ5FM42xLpHK...X6PymQu97KrGDJQY5Y"

5、向网页教程提交public key以便自动生成后续命令代码内容

此步只在教程中使用。

6、导入开发key

cleos wallet import

在提示输入钱包密码,并输入首次使用的系统默认帐号eosio的private key(5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3)之后,输出private key。

至此,你拥有一个默认的解锁的钱包,由key加载,并已得到保护。

 

特别说明:由于默认帐号eosio的公私钥是公开的,生产系统中最好仅用来创建首帐号,之后将其key从钱包中删除,否则会十分危险。

七、创建测试帐号

cleos create account eosio bob EOS59pZ8Wu75WDGeSD5cvEvJMfEia436rn4miLDQz6G9sHBJpS3f8 
cleos create account eosio alice EOS59pZ8Wu75WDGeSD5cvEvJMfEia436rn4miLDQz6G9sHBJpS3f8

注:创建了bob、alice两个帐号,EOS59pZ8Wu75WDGeSD5cvEvJMfEia436rn4miLDQz6G9sHBJpS3f8为上述的开发帐号的public key。操作必须在wallet unlock状态下进行。