EOS開發(fā)(1):如何搭建本地節(jié)點

最近準備研究EOS的合約開發(fā),第一步就是需要進行搭建本地節(jié)點,在網(wǎng)上查閱了一些資料,也踩了不少坑,最終發(fā)現(xiàn)還是官方文檔最靠譜:https://github.com/EOSIO/eos/wiki/Local-Environment

本文將介紹通過拉取eosio源代碼進行編譯啟動本地節(jié)點~

系統(tǒng)要求

  • MacOS Darwin 10.12或者更高 (推薦MacOS 10.13.x),其他系統(tǒng)可以在官方文檔查閱
  • 8G內(nèi)存,20G硬盤

編譯eosio源碼

首先拉取eos源碼:

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

拉取代碼需要一點時間,項目工程比較大。拉取完代碼后進入eos目錄,看到目前所在的分支是master,網(wǎng)上很多人推薦切換到dawn-2.x比較穩(wěn)定,這里我還是保持使用master分支。

執(zhí)行eosio_build.sh進行編譯:

./eosio_build.sh

這一步編譯會比較久,大概1個小時。編譯完成后會生成一個build目錄。

可執(zhí)行文件說明

在編譯完成后,在build/programs下可以看到很多可執(zhí)行文件夾,主要了解這幾個的功能。

  • nodeos - 服務端區(qū)塊鏈節(jié)點組件
  • cleos - 與區(qū)塊鏈交互和管理錢包的命令行工具
  • keosd -管理錢包的組件

如果想更方便使用上述指令,可以執(zhí)行:

cd build
sudo make install

這樣就可以全局使用這些指令了。

啟動節(jié)點

切換到eos/build/programs/nodeos目錄下,執(zhí)行./nodeos指令,這時候會程序會卡住不懂,不會進行挖礦,這是因為沒有進行文件配置。

進入~/Library/Application Support/eosio/nodeos/config目錄,修改config.ini文件:

# Track only transactions whose scopes involve the listed accounts. Default is to track all transactions. (eosio::account_history_plugin)
# filter_on_accounts =

# Limits the maximum time (in milliseconds) processing a single get_transactions call. (eosio::account_history_plugin)
get-transactions-time-limit = 3

# override the initial timestamp in the Genesis State file (eosio::chain_plugin)
# genesis-timestamp =

# the location of the block log (absolute path or relative to application data dir) (eosio::chain_plugin)
block-log-dir = "blocks"

# Pairs of [BLOCK_NUM,BLOCK_ID] that should be enforced as checkpoints. (eosio::chain_plugin)
# checkpoint =

# Limits the maximum time (in milliseconds) that a reversible block is allowed to run before being considered invalid (eosio::chain_plugin)
max-reversible-block-time = -1

# Limits the maximum time (in milliseconds) that is allowed a pushed transaction's code to execute before being considered invalid (eosio::chain_plugin)
max-pending-transaction-time = -1

# Limits the maximum time (in milliseconds) that is allowed a to push deferred transactions at the start of a block (eosio::chain_plugin)
max-deferred-transaction-time = 20

# Override default WASM runtime (eosio::chain_plugin)
# wasm-runtime =

# Time to wait, in milliseconds, between creating next faucet created account. (eosio::faucet_testnet_plugin)
faucet-create-interval-ms = 1000

# Name to use as creator for faucet created accounts. (eosio::faucet_testnet_plugin)
faucet-name = faucet

# [public key, WIF private key] for signing for faucet creator account (eosio::faucet_testnet_plugin)
faucet-private-key = ["EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"]

# The local IP and port to listen for incoming http connections. (eosio::http_plugin)
http-server-address = 127.0.0.1:8888

# Specify the Access-Control-Allow-Origin to be returned on each request. (eosio::http_plugin)
# access-control-allow-origin =

# Specify the Access-Control-Allow-Headers to be returned on each request. (eosio::http_plugin)
# access-control-allow-headers =

# Specify if Access-Control-Allow-Credentials: true should be returned on each request. (eosio::http_plugin)
access-control-allow-credentials = false

# The queue size between nodeos and MongoDB plugin thread. (eosio::mongo_db_plugin)
mongodb-queue-size = 256

# MongoDB URI connection string, see: https://docs.mongodb.com/master/reference/connection-string/. If not specified then plugin is disabled. Default database 'EOS' is used if not specified in URI. (eosio::mongo_db_plugin)
# mongodb-uri =

# The actual host:port used to listen for incoming p2p connections. (eosio::net_plugin)
p2p-listen-endpoint = 0.0.0.0:9876

# An externally accessible host:port for identifying this node. Defaults to p2p-listen-endpoint. (eosio::net_plugin)
# p2p-server-address =

# The public endpoint of a peer node to connect to. Use multiple p2p-peer-address options as needed to compose a network. (eosio::net_plugin)
# p2p-peer-address =

# The name supplied to identify this node amongst the peers. (eosio::net_plugin)
agent-name = "EOS Test Agent"

# Can be 'any' or 'producers' or 'specified' or 'none'. If 'specified', peer-key must be specified at least once. If only 'producers', peer-key is not required. 'producers' and 'specified' may be combined. (eosio::net_plugin)
allowed-connection = any

# Optional public key of peer allowed to connect.  May be used multiple times. (eosio::net_plugin)
# peer-key =

# Tuple of [PublicKey, WIF private key] (may specify multiple times) (eosio::net_plugin)
# peer-private-key =

# Log level: one of 'all', 'debug', 'info', 'warn', 'error', or 'off' (eosio::net_plugin)
log-level-net-plugin = info

# Maximum number of clients from which connections are accepted, use 0 for no limit (eosio::net_plugin)
max-clients = 25

# number of seconds to wait before cleaning up dead connections (eosio::net_plugin)
connection-cleanup-period = 30

# True to require exact match of peer network version. (eosio::net_plugin)
network-version-match = 0

# number of blocks to retrieve in a chunk from any individual peer during synchronization (eosio::net_plugin)
sync-fetch-span = 100

# Enable block production, even if the chain is stale. (eosio::producer_plugin)
enable-stale-production = true

# Percent of producers (0-100) that must be participating in order to produce blocks (eosio::producer_plugin)
required-participation = 33

# ID of producer controlled by this node (e.g. inita; may specify multiple times) (eosio::producer_plugin)
producer-name = eosio

# Tuple of [public key, WIF private key] (may specify multiple times) (eosio::producer_plugin)
private-key = ["EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"]

# The path of the wallet files (absolute path or relative to application data dir) (eosio::wallet_plugin)
wallet-dir = "."

# Timeout for unlocked wallet in seconds. Wallets will automatically lock after specified number of seconds of inactivity. Activity is defined as any wallet command e.g. list-wallets. (eosio::wallet_plugin)
# unlock-timeout =

# eosio key that will be imported automatically when a wallet is created. (eosio::wallet_plugin)
# eosio-key =

# Plugin(s) to enable, may be specified multiple times
# Load the block producer plugin, so you can produce blocks
plugin = eosio::producer_plugin
# Wallet plugin
plugin = eosio::wallet_api_plugin
# As well as API and HTTP plugins
plugin = eosio::chain_api_plugin
plugin = eosio::http_plugin

主要是需要配置:

  • http-server-address = 127.0.0.1:8888
  • enable-stale-production = true
  • producer-name = eosio
  • plugin = eosio::producer_plugin
  • plugin = eosio::wallet_api_plugin
  • plugin = eosio::chain_api_plugin
  • plugin = eosio::http_plugin

很多教程都說執(zhí)行完./nodeos指令后,還會生成一個gensis.json文件,但是我目前編譯的版本貌似已經(jīng)取消了這個配置文件,直接配置config.ini文件即可。

配置完后再次運行./nodeos指令,會看到本地節(jié)點正在運行,大概1秒鐘生成一個區(qū)塊。

如何驗證本地節(jié)點是否啟動成功

雖然看到了日志正在生成區(qū)塊,但是如何查看某些區(qū)塊的信息驗證呢?

使用cleos查看當前節(jié)點信息:

cleos -u http://localhost:8888 get info

查看某個區(qū)塊的信息:

cleos get block "2"
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容