【EOS】1.环境搭建

41次阅读

共计 3412 个字符,预计需要花费 9 分钟才能阅读完成。

官方文档
获取代码
git clone https://github.com/EOSIO/eos –recursive
# –recursive 表示自动获取更新子项目,相当于:
# git submodule update –init –recursive
4 中编译方式
自动编译脚本
笔者目前采取第一种方式编译,4 核 8G 的电脑编译了 2 个小时。

Docker Compose
手动编译
安装执行文件
配置 EOS
配置文件

配置文件地址:Linux: ~/.local/share/eosio/nodeos/config
区块文件:Linux:~/.local/share/eosio/nodeos/data

单节点网络
# 1. 命令行启动
$ cd build/programs/nodeos
$ ./nodeos -e -p eosio –plugin eosio::chain_api_plugin –plugin eosio::history_api_plugin

# 2. 通过配置 config.ini 方式
# Enable production on a stale chain, since a single-node test chain is pretty much always stale
enable-stale-production = true
# Enable block production with the testnet producers
producer-name = eosio
# Load the block producer plugin, so you can produce blocks
plugin = eosio::producer_plugin
# As well as API and HTTP plugins
plugin = eosio::chain_api_plugin
plugin = eosio::http_plugin
# This will be used by the validation step below, to view history
plugin = eosio::history_api_plugin
多节点网络

开启钱包管理
// 第一个窗口
$ keosd –http-server-address 127.0.0.1:8899
创建默认钱包
// 第二个窗口
$ cleos –wallet-url http://127.0.0.1:8899 wallet create –to-console
// 备份密码将来使用
Creating wallet: default
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
“PW5JsmfYz2wrdUEotTzBamUCAunAA8TeRZGT57Ce6PkvM12tre8Sm”
导入 eos key
上面步骤中启动的私有区块链是用默认的初始键创建的,该初始键必须加载到钱包中。
$ cleos –wallet-url http://127.0.0.1:8899 wallet import –private-key 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
imported private key for: EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
启动第一个生产节点
// 第三个窗口
$ nodeos –enable-stale-production –producer-name eosio –plugin eosio::chain_api_plugin –plugin eosio::net_api_plugin
启动第二个节点
这个命令在 ${EOSIO_SOURCE} 目录运行。在启动额外的节点之前,你必须先加载 eosio.bios 合约。该合约使您能够直接控制其他帐户的资源分配,并访问其他特权 API 调用。返回到第二个终端窗口,运行以下命令加载合同:
// 第二个窗口
$ cleos –wallet-url http://127.0.0.1:8899 set contract eosio build/contracts/eosio.bios
$ cleos create key
Private key: 5JgbL2ZnoEAhTudReWH1RnMuQS6DBeLZt4ucV6t8aymVEuYg7sr
Public key: EOS6hMjoWRF2L8x9YpeqtUEcsDKAyxSuM1APicxgRU1E3oyV5sDEg

$ cleos –wallet-url http://127.0.0.1:8899 wallet import 5JgbL2ZnoEAhTudReWH1RnMuQS6DBeLZt4ucV6t8aymVEuYg7sr
imported private key for: EOS6hMjoWRF2L8x9YpeqtUEcsDKAyxSuM1APicxgRU1E3oyV5sDEg

// 创建一个账户需要 2 个 public key; 一个是 owner key 和 active key. 这里 2 个 key 一样。
$ cleos –wallet-url http://127.0.0.1:8899 create account eosio inita EOS6hMjoWRF2L8x9YpeqtUEcsDKAyxSuM1APicxgRU1E3oyV5sDEg EOS6hMjoWRF2L8x9YpeqtUEcsDKAyxSuM1APicxgRU1E3oyV5sDEg
executed transaction: d1ea511977803d2d88f46deb554f5b6cce355b9cc3174bec0da45fc16fe9d5f3 352 bytes 102400 cycles
# eosio <= eosio::newaccount {“creator”:”eosio”,”name”:”inita”,”owner”:{“threshold”:1,”keys”:[{“key”:”EOS6hMjoWRF2L8x9YpeqtUEcsDK…
// 第四个窗口
$ nodeos –producer-name inita –plugin eosio::chain_api_plugin –plugin eosio::net_api_plugin –http-server-address 127.0.0.1:8889 –p2p-listen-endpoint 127.0.0.1:9877 –p2p-peer-address 127.0.0.1:9876 –config-dir node2 –data-dir node2 –private-key [\”EOS6hMjoWRF2L8x9YpeqtUEcsDKAyxSuM1APicxgRU1E3oyV5sDEg\”,\”5JgbL2ZnoEAhTudReWH1RnMuQS6DBeLZt4ucV6t8aymVEuYg7sr\”]

// 到这里,第二个节点是一个空闲的 producer。切换 producer,让 inita 变成 active producer,需要 bios node 操作
$ cleos –wallet-url http://127.0.0.1:8899 push action eosio setprods “{\”schedule\”: [{\”producer_name\”: \”inita\”,\”block_signing_key\”: \”EOS6hMjoWRF2L8x9YpeqtUEcsDKAyxSuM1APicxgRU1E3oyV5sDEg\”}]}” -p eosio@active
executed transaction: 2cff4d96814752aefaf9908a7650e867dab74af02253ae7d34672abb9c58235a 272 bytes 105472 cycles
# eosio <= eosio::setprods {“version”:1,”producers”:[{“producer_name”:”inita”,”block_signing_key”:”EOS6hMjoWRF2L8x9YpeqtUEcsDKA…
// 验证结果
cleos get info
cleos –url http://127.0.0.1:8889 get info

正文完
 0