作者:笼-中鸟 | 来源:互联网 | 2023-07-08 18:16
这篇文章主要为大家展示了“怎么使用docker和docker-compose在EOS本地Testnet上开发”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面
这篇文章主要为大家展示了“怎么使用docker和docker-compose在EOS本地Testnet上开发”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“怎么使用docker和docker-compose在EOS本地Testnet上开发”这篇文章吧。
EOS区块链的开发并不是立竿见影的,因为需要一些非显而易见的组件,需要对它们进行配置和协同工作。
我将学到什么?
如何运行和初始化EOS本地Testnet。
如何编译和运行EOS智能合约。
如何通过cleos进行EOS交易。
要求
要学习本教程,你需要使用下面的软件:
Ubuntu Linux(推荐)
docker/docker-compose
困难程度
教程内容
你可以直接在Linux操作系统上安装以下组件,但这样可以使你的开发环境更加干净,更易于维护和测试。
以下所有文件均为官方文件,并由EOSIO发布:
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 build -t my/eos .
docker-compose.yml(该软件应该如何运行)
正如我所说,需要一些配置来互相讨论所需的所有部分。
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'
运行
在新终端中运行以下命令:
docker-compose up
恭喜!你正在EOS Localnet中生成块!
初始化的乐趣尚未结束,因为你仍需要部署智能合约以获得EOS token货币!
cleos,命令行EOS钱包。
好的,EOS区块链正在运行,但现在我们需要另一个终端与它进行交互。
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中使用的块。
部署eosio.token,即EOS货币系统智能合约
目前没有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 &#39;[ "eosio", "1000000000.0000 EOS"]&#39; -p eosio.token@active
cleos push action eosio.token issue &#39;[ "testuser", "100000.0000 EOS", "m" ]&#39; -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 &#39;["testuser","eosio.token","10.0000 EOS",
"BUY LAMBOOO!!!"]&#39; -p testuser@active
cleos get currency balance eosio.token testuser
99990.0000 EOS
正如你在购买lambo后所看到的那样,EOS余额已经减少了,你使用了testuser权限来实现它。
每次初始化EOS区块链时,所有这些清除步骤都可以自动,分组和顺序执行。
以上是“怎么使用docker和docker-compose在EOS本地Testnet上开发”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程笔记行业资讯频道!