美文网首页区块链研习社EOS技术爱好者我爱编程
eos.io区块链平台安装构建搭建dapp开发环境

eos.io区块链平台安装构建搭建dapp开发环境

作者: 编程狂魔 | 来源:发表于2018-07-25 15:19 被阅读4次

    本文主要介绍如何构建在EOS平台运行的DApp开发环境。

    EOSIO构成组件

    EOSIO是由三个component组成的。

    image
    • nodeos:管理区块链节点的组件。
    • keosd:管理钱包的组件。
    • cleos:控制区块链和钱包CLI工具。

    安装EOSIO

    此文档以MacOS Darwin 10.12为基准。

    在EOSIO的github库下载源码。

    $ git clone https://github.com/EOSIO/eos --recursive
    

    要安装xcode和homebrew代码。如果还没有安装的情况,先设置xcodehomebrew

    源代码包含构建脚本及构建实现。

    $ cd eos
    $ ./eosio_build.sh
    

    如果成功的话,就会出现下面的信息。

    [100%] Linking CXX executable unit_test
    
    [100%] Built target unit_test
    
    _______  _______  _______ _________ _______
    
    (  ____ \(  ___  )(  ____ \\__   __/(  ___  )
    
    | (    \/| (   ) || (    \/   ) (   | (   ) |
    
    | (__    | |   | || (_____    | |   | |   | |
    
    |  __)   | |   | |(_____  )   | |   | |   | |
    
    | (      | |   | |      ) |   | |   | |   | |
    
    | (____/\| (___) |/\____) |___) (___| (___) |
    
    (_______/(_______)\_______)\_______/(_______)
    
    EOSIO has been successfully built. 00:11:21
    
    To verify your installation run the following commands:
    
    /usr/local/bin/mongod -f /usr/local/etc/mongod.conf &
    
    cd /Users/scion/git/eos/build; make test
    
    For more information:
    
    EOSIO website: https://eos.io
    
    EOSIO Telegram channel @ https://t.me/EOSProject
    
    EOSIO resources: https://eos.io/resources/
    
    EOSIO Stack Exchange: https://eosio.stackexchange.com
    
    EOSIO wiki: https://github.com/EOSIO/eos/wiki
    

    解决问题

    • 如果build过程中出现这样的error时:
    CMake Error at /usr/local/Cellar/cmake/3.11.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
     Failed to find Gettext libintl (missing: Intl_INCLUDE_DIR)
    Call Stack (most recent call first):
     /usr/local/Cellar/cmake/3.11.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
     /usr/local/Cellar/cmake/3.11.3/share/cmake/Modules/FindIntl.cmake:47 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
     programs/cleos/CMakeLists.txt:29 (find_package)
    

    应该是homebrewgettext连接到了不正确的版本,更改连接信息就可以了:

    $ brew link gettext — force
    

    在环境变量文件(~/.profile)添加gettoxt path:

    export PATH=”/usr/local/opt/gettext/bin:$PATH”
    

    参考:https://github.com/EOSIO/eos/issues/2174

    • 也有可能发生这种情况:
    Mac OS 10.13.3 build error “path mongo-cxx-driver already exists”
    

    这样解决:

    sudo rm -rf /tmp/mongo*
    cd /path/to/eos
    rm -rf build/
    git pull
    git submodule update — init — recursive
    ./eosio_build.sh
    

    参考:https://github.com/EOSIO/eos/issues/3197

    验证

    安装顺利完成。为了验证,执行下测试脚本。

    $ /usr/local/bin/mongod -f /usr/local/etc/mongod.conf &
    
    $ cd build/
    
    $ make test
    
    Running tests...
    
    Test project /Users/scion/git/eos/build
    
    Start  1: test_cypher_suites
    
    1/35 Test  #1: test_cypher_suites ...................   Passed    0.04 sec
    
    Start  2: validate_simple.token_abi
    
    2/35 Test  #2: validate_simple.token_abi ............   Passed    0.08 sec
    
    Start  3: validate_eosio.token_abi
    
    ...
    
    34/35 Test #34: restart-scenarios-test-hard_replay ...   Passed  151.83 sec
    
    Start 35: validate_dirty_db_test
    
    35/35 Test #35: validate_dirty_db_test ...............   Passed    4.42 sec
    
    100% tests passed, 0 tests failed out of 35
    

    下面完成安装:

    $ cd build
    
    $ sudo make install
    

    运行EOSIO

    试着运行EOSIO的组件吧。这是为了构建开发环境,所以可以先用一个节点。

    nodeos

    用带有option的命令直接执行就行了

    $ nodeos -e -p eosio --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin
    

    其中:

    • e : 区块生成
    • p eosio : 区块生产者名称
      — plugin eosio::chain_api_plugin : 区块链相关API插件
      — plugin eosio::history_api_plugin : 历史记录相关API插件

    可以用配置文件替换参数。

    • config file位置: ~/Library/Application Support/eosio/nodeos/config/config.ini
    • nodeos第一次运行时,该文件自动生成。
    $ vi ~/Library/Application\ Support/eosio/nodeos/config/config.ini
     
    ...
    # enable-stale-production = false
    enable-stale-production = true
    ...
    # producer-name =
    producer-name = eosio
    ...
    plugin = eosio::chain_api_plugin
    plugin = eosio::history_api_plugin
    ...
    

    执行nodeos :

    $ nodeos
    

    如果运行正常,可以看到在控制台上0.5秒生成block的信息。

    为了确认nodeos是否正常运行,让我们试试应用程序API接口。

    在运行于8888端口的应用软件服务上试试HTTP Request

    $ curl -k -v 'http://127.0.0.1:8888/v1/chain/get_info' -X GET
     
    Note: Unnecessary use of -X or --request, GET is already inferred.
    * Trying 127.0.0.1...
    * TCP_NODELAY set
    * Connected to 127.0.0.1 (127.0.0.1) port 8888 (#0)
    > GET /v1/chain/get_info HTTP/1.1
    > Host: 127.0.0.1:8888
    > User-Agent: curl/7.54.0
    > Accept: */*
    >
    < HTTP/1.1 200 OK
    < Connection: close
    < Content-Length: 529
    < Content-type: application/json
    < Server: WebSocket++/0.7.0
    <
    {"server_version":"012dc012","chain_id":"cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f","head_block_num":363,"last_irreversible_block_num":362,"last_irreversible_block_id":"0000016ad0238cef2f6a8de2098115ba155cbbc535122912a7a62f66097adbd6","head_block_id":"0000016b8cbb9154a759f2e61968fc1069fcf0ef9468886614d0538a97d96c61","head_block_time":"2018-06-12T07:10:59","head_block_producer":"eosio","virtual_block_cpu_limit":287075,"virtual_block_net_limit":1506023,"block_cpu_limit":199900,"block_net_limit":1048576}
    

    或是利用cleos命令执行。

    $ cleos get info
    {
      "server_version": "012dc012",
      "chain_id": "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f",
      "head_block_num": 580,
      "last_irreversible_block_num": 579,
      "last_irreversible_block_id": "000002436a1baaeb366b55995ddad7de0822f177d60a8c6e336e3f5fcb18ecc5",
      "head_block_id": "00000244e6923239c0649ddada0dd47a2df80df13fa825275df9ddac975e6162",
      "head_block_time": "2018-06-12T07:12:48",
      "head_block_producer": "eosio",
      "virtual_block_cpu_limit": 356561,
      "virtual_block_net_limit": 1871085,
      "block_cpu_limit": 199900,
      "block_net_limit": 1048576
    }
    

    keosd

    同样用带有option的命令直接执行就行了

    $ keosd — http-server-address=127.0.0.1:8900
    
    • http-server-address : REST API,nodeos默认端口是8888。cleos默认端口考虑使用8900,URL不可用。

    只能通过替换keosd配置文件选项来运行。

    • 配置文件位置:~/eosio-wallet/config.ini
    • 第一次keosd操作,文件自动生成。
    $ vi ~/eosio-wallet/config.ini
     
    # http-server-address = 127.0.0.1:8888
    http-server-address = 127.0.0.1:8900
    

    执行keosd:

    $ keosd
    

    在运行于8900端口的应用软件服务上试试HTTP Request

    $ curl -k -v ‘http://127.0.0.1:8900/v1/wallet/list_wallets' -X GET
    
    Note: Unnecessary use of -X or — request, GET is already inferred.
    * Trying 127.0.0.1…
    * TCP_NODELAY set
    * Connected to 127.0.0.1 (127.0.0.1) port 8900 (#0)
    > GET /v1/wallet/list_wallets HTTP/1.1
    > Host: 127.0.0.1:8900
    > User-Agent: curl/7.54.0
    > Accept: */*
    >
    < HTTP/1.1 200 OK
    < Connection: close
    < Content-Length: 2
    < Content-type: application/json
    < Server: WebSocket++/0.7.0
    <
    []
    

    或者使用cleos命令运行:

    $ cleos wallet list
    Wallets:
    []
    

    nodeoskeosd可以正常工作,现在可以使用EOSIO服务了。

    参考文件是EOSIO官方wiki文档,参考了本地环境的安装

    另:《EOS智能合约与DApp开发入门》教程已经上线,爱学习等不及的可以抓紧体验一下:

    EOS教程

    这个教程帮助你快速入门EOS区块链去中心化应用的开发,内容涵盖EOS工具链、账户与钱包、发行代币、智能合约开发与部署、使用代码与智能合约交互等核心知识点,最后综合运用React和EOS的各知识点完成一个便签DApp的开发。

    如果大家是学习以太坊的可以看这些教程:

    • web3j教程,主要是针对java和android程序员进行区块链以太坊开发的web3j详解。
    • 以太坊教程,主要介绍智能合约与dapp应用开发,适合入门。
    • 以太坊开发,主要是介绍使用node.js、mongodb、区块链、ipfs实现去中心化电商DApp实战,适合进阶。
    • python以太坊,主要是针对python工程师使用web3.py进行区块链以太坊开发的详解。
    • php以太坊,主要是介绍使用php进行智能合约开发交互,进行账号创建、交易、转账、代币开发以及过滤器和事件等内容。

    博客原文在:这里

    相关文章

      网友评论

        本文标题:eos.io区块链平台安装构建搭建dapp开发环境

        本文链接:https://www.haomeiwen.com/subject/pcwpmftx.html