EOS 开发:环境准备

May 12, 2018

这个系列选择使用 EOS New York 开发的 Docker 环境,需要具备基本的 docker 知识。

0. EOS 开发工具

eos 目前的开发生态大致如下图所示,其中

  • eosiocpp:编译 C++ 代码,能够上传到区块链上
  • cleos:命令行工具,用来和区块链交互
  • keosd:钱包管理器
  • nodeos:运行区块链的服务端软件

1. 下载镜像并测试运行

# 下载镜像
docker pull binaryfocus/eosdawn-2018-04-27-alpha-dev

# 运行 container
docker run --rm -it binaryfocus/eosdawn-2018-04-27-alpha-dev bash

# 运行 cleos
root@bc5d7d727921:/# cleos
ERROR: RequiredError: Subcommand required
Command Line Interface to EOSIO Client
Usage: cleos [OPTIONS] SUBCOMMAND

Options:
  -h,--help                   Print this help message and exit
  -u,--url TEXT=http://localhost:8888/
                              the http/https URL where nodeos is running
  --wallet-url TEXT=http://localhost:8888/
                              the http/https URL where keosd is running
  -v,--verbose                output verbose actions on error

Subcommands:
  version                     Retrieve version information
  create                      Create various items, on and off the blockchain
  get                         Retrieve various items and information from the blockchain
  set                         Set or update blockchain state
  transfer                    Transfer EOS from account to account
  net                         Interact with local p2p network connections
  wallet                      Interact with local wallet
  sign                        Sign a transaction
  push                        Push arbitrary transactions to the blockchain
  multisig                    Multisig contract commands
  system                      Send eosio.system contract action to the blockchain.

# 退出容器
root@bc5d7d727921:/# exit
exit

由于我们使用 —rm 运行的容器,在退出后会自动删除。

2. 创建 docker 网络

docker network 能够让容器之间进行通信。

docker network create eosnetwork

3. 运行容器

在 7777 端口上运行名为 server 的容器,并执行引号中的 nodeos 命令,启动服务:

docker run --name server --network=eosnetwork --rm -p 7777:7777 -i binaryfocus/eosdawn-2018-04-27-alpha-dev /bin/bash -c "nodeos -e -p eosio --plugin eosio::producer_plugin --plugin eosio::chain_api_plugin --plugin eosio::http_plugin -d /mnt/dev/data --http-server-address=0.0.0.0:7777 --access-control-allow-origin=*"

在 5555 端口上运行钱包:

docker run --name wallet --network=eosnetwork --rm -p 5555:5555 -i binaryfocus/eosdawn-2018-04-27-alpha-dev /bin/bash -c "keosd --http-server-address=0.0.0.0:5555"

再以 bash 启动一个容器,用来运行一些命令:

docker run --name tools --network=eosnetwork --rm -it binaryfocus/eosdawn-2018-04-27-alpha-dev /bin/bash

4. 测试

首先打开 http://localhost:7777/v1/chain/get_info 确保本地服务正常,然后输入下列命令测试是否 work:

root@0ad6e73c14f2:/# cleos -u http://server:7777 get info
{
  "server_version": "45fb9218",
  "head_block_num": 20660,
  "last_irreversible_block_num": 20659,
  "head_block_id": "000050b48f1b117aacfbe59fd5d66ca2fd6ecc16325d29206239e19c8861c902",
  "head_block_time": "2018-05-12T14:36:16",
  "head_block_producer": "eosio"
}

# 由于我们还没有创建钱包,所以返回为空
root@0ad6e73c14f2:/# cleos --wallet-url http://wallet:5555 wallet list keys
Wallets:
[]
[]

Reference


Profile picture

Written by Armin Li , a venture capitalist. [Weibo] [Subscribe]