【EOS】1.環境搭建

官方文檔

獲取代碼

git clone https://github.com/EOSIO/eos --recursive
# --recursive表示自動獲取更新子項目,至關於:
# git submodule update --init --recursive

4中編譯方式

自動編譯腳本

筆者目前採起第一種方式編譯,4核8G的電腦編譯了2個小時。node

clipboard.png

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

多節點網絡

clipboard.png

開啓錢包管理

// 第一個窗口
$ keosd --http-server-address 127.0.0.1:8899
// 實踐發現,上述步驟能夠省略,每次運行cleos命令,未開啓keosd會默認開啓一個服務。

建立默認錢包

// 第二個窗口
$ cleos  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

上面步驟中啓動的私有區塊鏈是用默認的初始鍵建立的,該初始鍵必須加載到錢包中。
在自動生成的config.ini文件中,我看到了同樣的私鑰對。ios

clipboard.png

$ cleos 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調用。返回到第二個終端窗口,運行如下命令加載合同:git

// 第二個窗口
// 遇到的坑 1.卡主不動沒法繼續運行,重啓電腦搞定。2.官網文檔沒有加"-p eosio",致使失敗。
$ cleos set contract eosio build/contracts/eosio.bios -p eosio
$ cleos create key
Private key: 5JgbL2ZnoEAhTudReWH1RnMuQS6DBeLZt4ucV6t8aymVEuYg7sr
Public key: EOS6hMjoWRF2L8x9YpeqtUEcsDKAyxSuM1APicxgRU1E3oyV5sDEg

$ cleos wallet import 5JgbL2ZnoEAhTudReWH1RnMuQS6DBeLZt4ucV6t8aymVEuYg7sr
imported private key for: EOS6hMjoWRF2L8x9YpeqtUEcsDKAyxSuM1APicxgRU1E3oyV5sDEg

// 建立一個帳戶須要2個public key;一個是owner key和active key. 這裏2個key同樣。
$ cleos 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 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
相關文章
相關標籤/搜索