最近准备研究EOS的合约开发,第一步就是需要进行搭建本地节点,在网上查阅了一些资料,也踩了不少坑,最终发现还是官方文档最靠谱:https://github.com/EOSIO/eos/wiki/Local-Environment
本文将介绍通过拉取eosio源代码进行编译启动本地节点~
系统要求
- MacOS Darwin 10.12或者更高 (推荐MacOS 10.13.x),其他系统可以在官方文档查阅
- 8G内存,20G硬盘
编译eosio源码
首先拉取eos源码:
git clone https://github.com/EOSIO/eos --recursive
拉取代码需要一点时间,项目工程比较大。拉取完代码后进入eos目录,看到目前所在的分支是master,网上很多人推荐切换到dawn-2.x比较稳定,这里我还是保持使用master分支。
执行eosio_build.sh进行编译:
./eosio_build.sh
这一步编译会比较久,大概1个小时。编译完成后会生成一个build目录。
可执行文件说明
在编译完成后,在build/programs下可以看到很多可执行文件夹,主要了解这几个的功能。
- nodeos - 服务端区块链节点组件
- cleos - 与区块链交互和管理钱包的命令行工具
- keosd -管理钱包的组件
如果想更方便使用上述指令,可以执行:
cd build
sudo make install
这样就可以全局使用这些指令了。
启动节点
切换到eos/build/programs/nodeos目录下,执行./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
很多教程都说执行完./nodeos指令后,还会生成一个gensis.json文件,但是我目前编译的版本貌似已经取消了这个配置文件,直接配置config.ini文件即可。
配置完后再次运行./nodeos指令,会看到本地节点正在运行,大概1秒钟生成一个区块。
如何验证本地节点是否启动成功
虽然看到了日志正在生成区块,但是如何查看某些区块的信息验证呢?
使用cleos查看当前节点信息:
cleos -u http://localhost:8888 get info
查看某个区块的信息:
cleos get block "2"