Dapp开发简明教程之配置环境

本文首发于kii.io。

最近在关注EOS生态,看到了一些很有意思的dapp,我想着自己写一个简易的dapp,看看它是怎么个玩法。

安装EOS Docker环境

我们根据官网上的EOS.IO developer guide装一下Docker环境。

  1. 拉取eos-dev镜像
docker pull eosio/eos-dev:v1.5.2
  1. 为nodeos和keosd创建一个共享网络
docker network create eosdev
  1. 运行nodeos节点,并且转发docker container内的8888端口到本机8888端口
docker run --name nodeos -d -p 8888:8888 --network eosdev -v /tmp/eosio/work:/work -v /tmp/eosio/data:/mnt/dev/data -v /tmp/eosio/config:/mnt/dev/config eosio/eos-dev

# 进入刚刚创建的docker
docker execi -it nodeos /bin/bash
# 在创建的container中运行nodeos
nodeos -e -p eosio --plugin eosio::producer_plugin --plugin eosio::history_plugin --plugin eosio::chain_api_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:8888 --access-control-allow-origin=* --contracts-console --http-validate-host=false --replay-blockchain
exit
  1. 运行Keosd(钱包和密钥)
docker run -d --name keosd --network=eosdev -i eosio/eos-dev /bin/bash -c "keosd --http-server-address=0.0.0.0:9876"
  1. 验证安装是否完成
docker logs --tail 10 nodeos

输出应该类似这样:

info  2018-12-27T13:10:57.501 thread-0  producer_plugin.cpp:1522      produce_block        ] Produced block 00000fbc2cbb5329... #4028 @ 2018-12-27T13:10:57.500 signed by eosio [trxs: 0, lib: 4027, confirmed: 0]
info  2018-12-27T13:10:58.001 thread-0  producer_plugin.cpp:1522      produce_block        ] Produced block 00000fbdec5c5827... #4029 @ 2018-12-27T13:10:58.000 signed by eosio [trxs: 0, lib: 4028, confirmed: 0]
info  2018-12-27T13:10:58.502 thread-0  producer_plugin.cpp:1522      produce_block        ] Produced block 00000fbe9b7edada... #4030 @ 2018-12-27T13:10:58.500 signed by eosio [trxs: 0, lib: 4029, confirmed: 0]
info  2018-12-27T13:10:59.002 thread-0  producer_plugin.cpp:1522      produce_block        ] Produced block 00000fbf6fe1b9f6... #4031 @ 2018-12-27T13:10:59.000 signed by eosio [trxs: 0, lib: 4030, confirmed: 0]
info  2018-12-27T13:10:59.502 thread-0  producer_plugin.cpp:1522      produce_block        ] Produced block 00000fc0249bc603... #4032 @ 2018-12-27T13:10:59.500 signed by eosio [trxs: 0, lib: 4031, confirmed: 0]
info  2018-12-27T13:11:00.004 thread-0  producer_plugin.cpp:1522      produce_block        ] Produced block 00000fc1313d03fa... #4033 @ 2018-12-27T13:11:00.000 signed by eosio [trxs: 0, lib: 4032, confirmed: 0]
info  2018-12-27T13:11:00.504 thread-0  producer_plugin.cpp:1522      produce_block        ] Produced block 00000fc229fdc290... #4034 @ 2018-12-27T13:11:00.500 signed by eosio [trxs: 0, lib: 4033, confirmed: 0]
info  2018-12-27T13:11:01.007 thread-0  producer_plugin.cpp:1522      produce_block        ] Produced block 00000fc3dc86543f... #4035 @ 2018-12-27T13:11:01.000 signed by eosio [trxs: 0, lib: 4034, confirmed: 0]
info  2018-12-27T13:11:01.502 thread-0  producer_plugin.cpp:1522      produce_block        ] Produced block 00000fc4032f345d... #4036 @ 2018-12-27T13:11:01.500 signed by eosio [trxs: 0, lib: 4035, confirmed: 0]
info  2018-12-27T13:11:02.002 thread-0  producer_plugin.cpp:1522      produce_block        ] Produced block 00000fc514623d3e... #4037 @ 2018-12-27T13:11:02.000 signed by eosio [trxs: 0, lib: 4036, confirmed: 0]
  1. 进入钱包看一下
docker exec -it keosd bash
cleos --wallet-url http://127.0.0.1:9876 wallet list keys

此时,我们应该能看到类似

Wallets:
[]

这就表明,截止目前,我们的安装都是正确的。

查看endpoint信息

访问本地的http://localhost:8888/v1/chain/get_info,获取以下内容:


{
  "server_version": "3186ddba",
  "chain_id": "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f",
  "head_block_num": 9346,
  "last_irreversible_block_num": 9345,
  "last_irreversible_block_id": "000024819997cea0b5d747294c68726500660793cab106e44a7b6e49f88353a7",
  "head_block_id": "000024829ab39a32e482b099daeefacc2f2fcb4b76e9f25702915c055850ec7c",
  "head_block_time": "2018-12-27T13:55:17.500",
  "head_block_producer": "eosio",
  "virtual_block_cpu_limit": 200000000,
  "virtual_block_net_limit": 1048576000,
  "block_cpu_limit": 199900,
  "block_net_limit": 1048576,
  "server_version_string": "v1.6.0-rc1"
}

cleos是一个用于在keosd和nodeos之间交互的工具。我们先拿到keosd的IP信息,执行

docker network inspect eosdev

获得如下返回:

[
    {
        "Name": "eosdev",
        "Id": "fe1b358085ee23b67c4fac9c8a385a75c3ac3bbb26c93fba67e2454d73852ff5",
        "Created": "2018-12-27T12:35:19.845673056Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.21.0.0/16",
                    "Gateway": "172.21.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "39887d21ad4dcac7069f0fa7ac036a4c3755b12c1f307967ed553ded13631002": {
                "Name": "keosd",
                "EndpointID": "fa817d5193fec763427d346ffb3d9cfa1084efed65f5063d4cb21265f79fa297",
                "MacAddress": "02:42:ac:15:00:03",
                "IPv4Address": "172.21.0.3/16",
                "IPv6Address": ""
            },
            "a4333f9a87c053adf267e07b49b1e1ea869fe9eaa862fffd994c8f3c5fd26852": {
                "Name": "nodeos",
                "EndpointID": "1a1434c513d5225d1a53af32de0d09b120bb338bd3da4240ff887a0c485a0e67",
                "MacAddress": "02:42:ac:15:00:02",
                "IPv4Address": "172.21.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

这里面的172.21.0.2就是keosd的地址,我们创建如下的alias。

alias cleos='docker exec -it nodeos /opt/eosio/bin/cleos --url http://127.0.0.1:8888 --wallet-url http://172.21.0.3:9876'

注意把172.21.0.3替换成你自己的keosd的IP地址

执行一下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://127.0.0.1:8888/
                              the http/https URL where nodeos is running
  --wallet-url TEXT=unix:///root/eosio-wallet/keosd.sock
                              the http/https URL where keosd is running
  -r,--header                 pass specific HTTP header; repeat this option to pass multiple headers
  -n,--no-verify              don't verify peer certificate when using HTTPS
  --no-auto-keosd             don't automatically launch a keosd if one is not currently running
  -v,--verbose                output verbose actions on error
  --print-request             print HTTP request to STDERR
  --print-response            print HTTP response to STDERR

Subcommands:
  version                     Retrieve version information
  create                      Create various items, on and off the blockchain
  convert                     Pack and unpack transactions
  get                         Retrieve various items and information from the blockchain
  set                         Set or update blockchain state
  transfer                    Transfer tokens 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
  wrap                        Wrap contract commands
  system                      Send eosio.system contract action to the blockchain.

如果是的话,恭喜你,配置成功。我们开发前的准备工作就完成啦!

Ref:

  1. eos developer guide
  2. eos wiki

专注数字货币、高并发、中间件。欢迎关注微信公众号。

Dapp开发简明教程之配置环境_第1张图片

你可能感兴趣的:(EOS)