EOS區塊鏈的開發並非立竿見影的,由於須要一些非顯而易見的組件,須要對它們進行配置和協同工做。前端
要學習本教程,你須要使用下面的軟件:node
你能夠直接在Linux操做系統上安裝如下組件,但這樣可使你的開發環境更加乾淨,更易於維護和測試。git
如下全部文件均爲官方文件,並由EOSIO發佈:github
FROM ubuntu:18.04 RUN apt-get update && apt-get install -y curl libicu60 libusb-1.0-0 libcurl3-gnutls RUN curl -LO https://github.com/EOSIO/eos/releases/download/v1.7.0/eosio_1.7.0-1-ubuntu-18.04_amd64.deb \ && dpkg -i eosio_1.7.0-1-ubuntu-18.04_amd64.deb RUN curl -LO https://github.com/EOSIO/eosio.cdt/releases/download/v1.6.1/eosio.cdt_1.6.1-1_amd64.deb \ && dpkg -i eosio.cdt_1.6.1-1_amd64.deb RUN curl -LO https://github.com/EOSIO/eosio.cdt/archive/v1.6.1.tar.gz && tar -xvzf v1.6.1.tar.gz --one-top-level=eosio.cdt --strip-components 1 RUN cd /eosio.cdt/ && curl -LO https://github.com/EOSIO/eosio.contracts/archive/v1.6.0-rc3.tar.gz && tar -xvzf v1.6.0-rc3.tar.gz --one-top-level=eosio.contracts --strip-components 1
你可使用如下命令生成打包的鏡像沙箱:docker
docker build -t my/eos .
正如我所說,須要一些配置來互相討論所需的全部部分。編程
default.wallet
是一個預配置的錢包,帶有用於測試的私鑰。config.ini
是Block Producer(BP)的文件,在EOS Mainnet中你不會/不能改變它。version: '3' services: nodeos: container_name: nodeos image: my/eos command: 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 --http-server-address=0.0.0.0:8888 --access-control-allow-origin=* --contracts-console --http-validate-host=false --filter-on="*" stop_grace_period: 3m0s volumes: - ./:/eosio.cdt/contract - ./config.ini:/root/.local/share/eosio/nodeos/config/config.ini ports: - '8888:8888' - '9830:9876' depends_on: - keosd keosd: container_name: keosd hostname: keosd image: my/eos command: keosd --http-server-address=0.0.0.0:8901 --http-validate-host 0 --verbose-http-errors --unlock-timeout=9999999 volumes: - ./default.wallet:/root/eosio-wallet/default.wallet expose: - 8901 ports: - '8901:8901'
在新終端中運行如下命令:bootstrap
docker-compose up
恭喜!你正在EOS Localnet中生成塊!ubuntu
初始化的樂趣還沒有結束,由於你仍須要部署智能合約以得到EOS token貨幣!api
好的,EOS區塊鏈正在運行,但如今咱們須要另外一個終端與它進行交互。bash
alias cleos="docker exec -it nodeos cleos --url http://127.0.0.1:8888 --wallet-url http://keosd:8901" cleos get info
{ "server_version": "686f0deb", "chain_id": "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f", "head_block_num": 85, "last_irreversible_block_num": 84, "last_irreversible_block_id": "000000541c75df656485edb9fb71e898db933c78f685fc7a8d883544d141350d", "head_block_id": "0000005580f8983a211e4dcddbb783d6bc962726ef271beeee54b63bd906b5a0", "head_block_time": "2019-03-30T09:37:33.500", "head_block_producer": "eosio", "virtual_block_cpu_limit": 217493, "virtual_block_net_limit": 1140464, "block_cpu_limit": 199900, "block_net_limit": 1048576, "server_version_string": "v1.7.0" }
正如你在輸出中看到的,最新的塊是85,而chain_is是testnet中使用的塊。
目前沒有EOS token,因此讓咱們添加它們,
編譯它們:
docker exec -it nodeos bash -c "cd /eosio.cdt/eosio.contracts/contracts/ && eosio-cpp -I eosio.token/include/ -abigen -o eosio.token/src/eosio.token.wasm eosio.token/src/eosio.token.cpp"
建立eosio.token
賬戶併發布智能合約:
cleos create account eosio eosio.token EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV executed transaction: d196c673f38085e34815900dd47de8ba030d14ed9d7311a1a173df131281e66a 200 bytes 2568 us # eosio <= eosio::newaccount {"creator":"eosio","name":"eosio.token","owner":{"threshold":1,"keys":[{"key":"EOS6MRyAjQq8ud7hVNYcf... warning: transaction executed locally, but may not be confirmed by the network yet ] cleos set contract eosio.token /eosio.cdt/eosio.contracts/contracts/eosio.token/src eosio.token.wasm eosio.token.abi -p eosio.token@active Reading WASM from /eosio.cdt/eosio.contracts/contracts/eosio.token/src/eosio.token.wasm... Publishing contract... executed transaction: 1b4b532337035ad4cd985d1cb63c844b84671ed574251a85519fc51c8fb4f290 9592 bytes 10523 us # eosio <= eosio::setcode {"account":"eosio.token","vmtype":0,"vmversion":0,"code":"0061736d0100000001bb011f60000060037f7e7f00... # eosio <= eosio::setabi {"account":"eosio.token","abi":"0e656f73696f3a3a6162692f312e310008076163636f756e7400010762616c616e63... warning: transaction executed locally, but may not be confirmed by the network yet ]
建立你的testuser賬戶,並給本身一些免費的錢!:D
cleos create account eosio testuser EOS6K42yrrMETmx2rXFJeKtaGrQAwgCDBYUVY7PGCVfhWFykqvhVR EOS6K42yrrMETmx2rXFJeKtaGrQAwgCDBYUVY7PGCVfhWFykqvhVR cleos push action eosio.token create '[ "eosio", "1000000000.0000 EOS"]' -p eosio.token@active cleos push action eosio.token issue '[ "testuser", "100000.0000 EOS", "m" ]' -p eosio@active
恭喜你,如今你是富翁了!
cleos get currency balance eosio.token testuser 100000.0000 EOS cleos get table eosio.token testuser accounts { "rows": [{ "balance": "100000.0000 EOS" } ], "more": false }
你的第一筆交易:
cleos push action eosio.token transfer '["testuser","eosio.token","10.0000 EOS", "BUY LAMBOOO!!!"]' -p testuser@active cleos get currency balance eosio.token testuser 99990.0000 EOS
正如你在購買lambo後所看到的那樣,EOS餘額已經減小了,你使用了testuser權限來實現它。
每次初始化EOS區塊鏈時,全部這些清除步驟均可以自動,分組和順序執行。
咱們已經簡要介紹瞭如何使用docker和一些基本測試來設置本地EOS Testnet。cleos
和docker
的美妙之處在於咱們能夠在幾分鐘內自動化AD,擁有一個乾淨的新工做EOS環境。全部命令都不須要手動執行,咱們能夠將它們放在自定義bootstrap.sh
中,以便在須要時從新建立所需的環境。
======================================================================
分享一些EOS區塊鏈相關的交互式在線編程實戰教程:
- EOS入門教程,本課程幫助你快速入門EOS區塊鏈去中心化應用的開發,內容涵蓋EOS工具鏈、帳戶與錢包、發行代幣、智能合約開發與部署、使用代碼與智能合約交互等核心知識點,最後綜合運用各知識點完成一個便籤DApp的開發。
- 深刻淺出玩轉EOS錢包開發,本課程以手機EOS錢包的完整開發過程爲主線,深刻學習EOS區塊鏈應用開發,課程內容即涵蓋帳戶、計算資源、智能合約、動做與交易等EOS區塊鏈的核心概念,同時也講解如何使用eosjs和eosjs-ecc開發包訪問EOS區塊鏈,以及如何在React前端應用中集成對EOS區塊鏈的支持。課程內容深刻淺出,很是適合前端工程師深刻學習EOS區塊鏈應用開發。
匯智網原創翻譯,轉載請標明出處。這裏是如何使用docker和docker-compose在EOS本地Testnet上開發