EOS在ubuntu16.04搭建私有链(一)

EOS,可以理解为Enterprise Operation System,即为商用分布式应用设计的一款区块链操作系统。EOS是引入的一种新的区块链架构,旨在实现分布式应用的性能扩展。想要全面的了解EOS,通过搭建eos私有链是不错的方法,下来接我将介绍在ubuntu16.04的环境下搭建eos私有链的过程。

1.源码编译的心酸过程
最初,通过网上博客git源码,然后通过官方提供的编译脚本进行整体自动化编译,其大概步骤如下:

1.下载最新的源码
git clone https://github.com/EOSIO/eos --recursive

2.整体编译
sudo  ./eos/ipts/eosio_build.sh

很不幸,编译没有通过,大概错误如下:
在这里插入图片描述
总是提示mongoDB数据库的插件缺失,检查mongoDB数据库安装无误。查询国内和国外网站,有些说是国内连接下载mongoDB数据库不能用,依据他们的步骤进行编译也任然无果。中间也换过编译机,最后没有办法只能放弃源码额编译,在网上下载编译好的结果,下载链接和安装步骤如下:

1.添加下载链接


2.安装
sudo apt-get install ./eosio_1.5.2-1-ubuntu-16.04_amd64.deb

安装完成后系统命令新增 :
nodeos :通过配置不同插件,启动节点,同步EOS网络数据或者自己生成块,也可作为API节点供调用
keosd:管理钱包,钱包中包含EOS公私钥对信息
cleos:命令行交互接口,连接钱包与EOS网络,执行查看网络信息,推送交易信息,部署智能合约等

2.节点的启动
eos的节点是通过nodeos的命令启动的,下面先简要介绍一下nodeos命令:

nodeos 
-h     #查看帮助
-v     #查看版本信息
--data-dir ./data/ # 区块数据目录
--config-dir ./    # 配置文件目录
--delete-all-blocks # 删除区块
--genesis-json genesis.json  # 创世区块文件

启动需要的配置文件:

# the endpoint upon which to listen for incoming connections (eosio::bnet_plugin)
bnet-endpoint = 0.0.0.0:4321

# this peer will request only irreversible blocks from other nodes (eosio::bnet_plugin)
bnet-follow-irreversible = 0

# the number of threads to use to process network messages (eosio::bnet_plugin)
# bnet-threads = 

# remote endpoint of other node to connect to; Use multiple bnet-connect options as needed to compose a network (eosio::bnet_plugin)
# bnet-connect = 

# this peer will request no pending transactions from other nodes (eosio::bnet_plugin)
bnet-no-trx = false

# The string used to format peers when logging messages about them.  Variables are escaped with ${<variable name>}.
# Available Variables:
#    _name  	self-reported name
# 
#    _id    	self-reported ID (Public Key)
# 
#    _ip    	remote IP address of peer
# 
#    _port  	remote port number of peer
# 
#    _lip   	local IP address connected to peer
# 
#    _lport 	local port number connected to peer
# 
#  (eosio::bnet_plugin)
bnet-peer-log-format = ["${_name}" ${_ip}:${_port}]

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

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

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

# Override default maximum ABI serialization time allowed in ms (eosio::chain_plugin)
abi-serializer-max-time-ms = 15000

# Maximum size (in MiB) of the chain state database (eosio::chain_plugin)
chain-state-db-size-mb = 1024

# Safely shut down node when free space remaining in the chain state database drops below this size (in MiB). (eosio::chain_plugin)
chain-state-db-guard-size-mb = 128

# Maximum size (in MiB) of the reversible blocks database (eosio::chain_plugin)
reversible-blocks-db-size-mb = 340

# Safely shut down node when free space remaining in the reverseible blocks database drops below this size (in MiB). (eosio::chain_plugin)
reversible-blocks-db-guard-size-mb = 2

# Number of worker threads in controller thread pool (eosio::chain_plugin)
chain-threads = 2

# print contract's output to console (eosio::chain_plugin)
contracts-console = false

# Account added to actor whitelist (may specify multiple times) (eosio::chain_plugin)
# actor-whitelist = 

# Account added to actor blacklist (may specify multiple times) (eosio::chain_plugin)
# actor-blacklist = 

# Contract account added to contract whitelist (may specify multiple times) (eosio::chain_plugin)
# contract-whitelist = 

# Contract account added to contract blacklist (may specify multiple times) (eosio::chain_plugin)
# contract-blacklist = 

# Action (in the form code::action) added to action blacklist (may specify multiple times) (eosio::chain_plugin)
# action-blacklist = 

# Public key added to blacklist of keys that should not be included in authorities (may specify multiple times) (eosio::chain_plugin)
# key-blacklist = 

# Deferred transactions sent by accounts in this list do not have any of the subjective whitelist/blacklist checks applied to them (may specify multiple times) (eosio::chain_plugin)
# sender-bypass-whiteblacklist = 

# Database read mode ("speculative", "head", or "read-only").
# In "speculative" mode database contains changes done up to the head block plus changes made by transactions not yet included to the blockchain.
# In "head" mode database contains changes done up to the current head block.
# In "read-only" mode database contains incoming block changes but no speculative transaction processing.
#  (eosio::chain_plugin)
read-mode = speculative

# Chain validation mode ("full" or "light").
# In "full" mode all incoming blocks will be fully validated.
# In "light" mode all incoming blocks headers will be fully validated; transactions in those validated blocks will be trusted 
#  (eosio::chain_plugin)
validation-mode = full

# Disable the check which subjectively fails a transaction if a contract bills more RAM to another account within the context of a notification handler (i.e. when the receiver is not the code of the action). (eosio::chain_plugin)
disable-ram-billing-notify-checks = false

# Indicate a producer whose blocks headers signed by it will be fully validated, but transactions in those validated blocks will be trusted. (eosio::chain_plugin)
# trusted-producer = 

# Track actions which match receiver:action:actor. Actor may be blank to include all. Action and Actor both blank allows all from Recieiver. Receiver may not be blank. (eosio::history_plugin)
# filter-on = 

# Do not track actions which match receiver:action:actor. Action and Actor both blank excludes all from Reciever. Actor blank excludes all from reciever:action. Receiver may not be blank. (eosio::history_plugin)
# filter-out = 

# PEM encoded trusted root certificate (or path to file containing one) used to validate any TLS connections made.  (may specify multiple times)
#  (eosio::http_client_plugin)
# https-client-root-cert = 

# true: validate that the peer certificates are valid and trusted, false: ignore cert errors (eosio::http_client_plugin)
https-client-validate-peers = 1

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

# The local IP and port to listen for incoming https connections; leave blank to disable. (eosio::http_plugin)
# https-server-address = 

# Filename with the certificate chain to present on https connections. PEM format. Required for https. (eosio::http_plugin)
# https-certificate-chain-file = 

# Filename with https private key in PEM format. Required for https (eosio::http_plugin)
# https-private-key-file = 

# 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 the Access-Control-Max-Age to be returned on each request. (eosio::http_plugin)
# access-control-max-age = 

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

# The maximum body size in bytes allowed for incoming RPC requests (eosio::http_plugin)
max-body-size = 1048576

# Append the error log to HTTP responses (eosio::http_plugin)
verbose-http-errors = false

# If set to false, then any incoming "Host" header is considered valid (eosio::http_plugin)
http-validate-host = 1

# Additionaly acceptable values for the "Host" header of incoming HTTP requests, can be specified multiple times.  Includes http/s_server_address by default. (eosio::http_plugin)
# http-alias = 

# The maximum number of pending login requests (eosio::login_plugin)
max-login-requests = 1000000

# The maximum timeout for pending login requests (in seconds) (eosio::login_plugin)
max-login-timeout = 60

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

# The maximum size of the abi cache for serializing data. (eosio::mongo_db_plugin)
mongodb-abi-cache-size = 2048

# Required with --replay-blockchain, --hard-replay-blockchain, or --delete-all-blocks to wipe mongo db.This option required to prevent accidental wipe of mongo db. (eosio::mongo_db_plugin)
mongodb-wipe = false

# If specified then only abi data pushed to mongodb until specified block is reached. (eosio::mongo_db_plugin)
mongodb-block-start = 0

# 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. Example: mongodb://127.0.0.1:27017/EOS (eosio::mongo_db_plugin)
# mongodb-uri = 

# Update blocks/block_state with latest via block number so that duplicates are overwritten. (eosio::mongo_db_plugin)
mongodb-update-via-block-num = 0

# Enables storing blocks in mongodb. (eosio::mongo_db_plugin)
mongodb-store-blocks = 1

# Enables storing block state in mongodb. (eosio::mongo_db_plugin)
mongodb-store-block-states = 1

# Enables storing transactions in mongodb. (eosio::mongo_db_plugin)
mongodb-store-transactions = 1

# Enables storing transaction traces in mongodb. (eosio::mongo_db_plugin)
mongodb-store-transaction-traces = 1

# Enables storing action traces in mongodb. (eosio::mongo_db_plugin)
mongodb-store-action-traces = 1

# Track actions which match receiver:action:actor. Receiver, Action, & Actor may be blank to include all. i.e. eosio:: or :transfer:  Use * or leave unspecified to include all. (eosio::mongo_db_plugin)
# mongodb-filter-on = 

# Do not track actions which match receiver:action:actor. Receiver, Action, & Actor may be blank to exclude all. (eosio::mongo_db_plugin)
# mongodb-filter-out = 

# 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 = 

# Maximum number of client nodes from any single IP address (eosio::net_plugin)
p2p-max-nodes-per-host = 1

# 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 = 

# 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

# max connection cleanup time per cleanup call in millisec (eosio::net_plugin)
max-cleanup-time-msec = 10

# 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

# maximum sizes of transaction or block messages that are sent without first sending a notice (eosio::net_plugin)
max-implicit-request = 1500

# Enable expirimental socket read watermark optimization (eosio::net_plugin)
use-socket-read-watermark = 0

# The string used to format peers when logging messages about them.  Variables are escaped with ${<variable name>}.
# Available Variables:
#    _name  	self-reported name
# 
#    _id    	self-reported ID (64 hex characters)
# 
#    _sid   	first 8 characters of _peer.id
# 
#    _ip    	remote IP address of peer
# 
#    _port  	remote port number of peer
# 
#    _lip   	local IP address connected to peer
# 
#    _lport 	local port number connected to peer
# 
#  (eosio::net_plugin)
peer-log-format = ["${_name}" ${_ip}:${_port}]

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

# Start this node in a state where production is paused (eosio::producer_plugin)
pause-on-startup = false

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

# Limits the maximum age (in seconds) of the DPOS Irreversible Block for a chain this node will produce blocks on (use negative value to indicate unlimited) (eosio::producer_plugin)
max-irreversible-block-age = -1

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

# (DEPRECATED - Use signature-provider instead) Tuple of [public key, WIF private key] (may specify multiple times) (eosio::producer_plugin)
# private-key = 

# Key=Value pairs in the form <public-key>=<provider-spec>
# Where:
#    <public-key>    	is a string form of a vaild EOSIO public key
# 
#    <provider-spec> 	is a string in the form <provider-type>:<data>
# 
#    <provider-type> 	is KEY, or KEOSD
# 
#    KEY:<data>      	is a string form of a valid EOSIO private key which maps to the provided public key
# 
#    KEOSD:<data>    	is the URL where keosd is available and the approptiate wallet(s) are unlocked (eosio::producer_plugin)
signature-provider = EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV=KEY:5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3

# Limits the maximum time (in milliseconds) that is allowd for sending blocks to a keosd provider for signing (eosio::producer_plugin)
keosd-provider-timeout = 5

# account that can not access to extended CPU/NET virtual resources (eosio::producer_plugin)
# greylist-account = 

# offset of non last block producing time in microseconds. Negative number results in blocks to go out sooner, and positive number results in blocks to go out later (eosio::producer_plugin)
produce-time-offset-us = 0

# offset of last block producing time in microseconds. Negative number results in blocks to go out sooner, and positive number results in blocks to go out later (eosio::producer_plugin)
last-block-time-offset-us = 0

# ratio between incoming transations and deferred transactions when both are exhausted (eosio::producer_plugin)
incoming-defer-ratio = 1

# the location of the snapshots directory (absolute path or relative to application data dir) (eosio::producer_plugin)
snapshots-dir = "snapshots"

# the location of the state-history directory (absolute path or relative to application data dir) (eosio::state_history_plugin)
state-history-dir = "state-history"

# enable trace history (eosio::state_history_plugin)
trace-history = false

# enable chain state history (eosio::state_history_plugin)
chain-state-history = false

# the endpoint upon which to listen for incoming connections (eosio::state_history_plugin)
state-history-endpoint = 0.0.0.0:8080

# Lag in number of blocks from the head block when selecting the reference block for transactions (-1 means Last Irreversible Block) (eosio::txn_test_gen_plugin)
txn-reference-block-lag = 0

# Plugin(s) to enable, may be specified multiple times
# plugin = 
plugin = eosio::chain_api_plugin
plugin = eosio::chain_plugin
plugin = eosio::producer_plugin
plugin = eosio::http_plugin
plugin = eosio::net_plugin
plugin = eosio::net_api_plugin

关于config.ini配置中相关字段的说明请参照:https://eosfans.io/topics/930
接下来我们创建一个eos目录,在该目录下创建data和config目录,将上述的config.ini配置放入到config目录下,运行
nodeos -e -p eosio --data-dir ./data --config-dir ./config
命令启动一个主节点,效果如下图:
在这里插入图片描述
系统每隔0.5秒产生一个区块。

3.钱包管理
3.1创建钱包

命令:
	cleos wallet create -n 钱包名称 --to-console
eg:
	cleos wallet create -n  eosio.wallet --to-console
	"/usr/opt/eosio/1.5.2/bin/keosd" launched
	Creating wallet: eosio.wallet
	Save password to use in the future to unlock this wallet.
	Without password imported keys will not be retrievable.
	"PW5JvZZ4yAcD2AbsgMTTWACsdAS2ntbKZnN1eHpkCZfBzRj327Yv5"

其中"PW5JvZZ4yAcD2AbsgMTTWACsdAS2ntbKZnN1eHpkCZfBzRj327Yv5"为钱包密码

3.2创建密钥

命令:
	cleos create key --to-console
返回:
	Private key: 5KR4WL7sR1FZmcPWv4ebLofX8sbfhh2pjoyziaz4qEnNr8spVX7
	Public key: EOS5hKhB4apdoLs2mPGw95NjavbyuqW6PPrAas2hgfWnHDA6dnnEu

3.3解锁钱包

命令:
	cleos wallet unlock -n 钱包名称 --password 钱包密码
eg:
	cleos wallet unlock -n eosio.wallet --password PW5JvZZ4yAcD2AbsgMTTWACsdAS2ntbKZnN1eHpkCZfBzRj327Yv5
	Unlocked: eosio.wallet

3.4密钥导入钱包

命令:
	cleos wallet import -n 钱包名称  --private-key 私钥
eg:
	cleos wallet import -n eosio.wallet --private-key 5KR4WL7sR1FZmcPWv4ebLofX8sbfhh2pjoyziaz4qEnNr8spVX7
	imported private key for: EOS5hKhB4apdoLs2mPGw95NjavbyuqW6PPrAas2hgfWnHDA6dnnEu

3.5查询钱包列表

命令:
	cleos wallet list
返回:
	Wallets:
[
  "eosio.wallet *"
]
注:钱包名后面跟随 ‘*’表示钱包处于unlock状态

3.6查询私钥列表

命令:
	cleos wallet keys
返回:
	[
       "EOS5gdTnScL5DTVPxknPKgzfD26SBEkSyepb9Em35u7mKyQzEyq9k",
       "EOS8V4guYfFbmxmk4Xt2Ae9d96kz2RxYeZKmNkh6CBf8kd7vumzMJ"
    ]

3.7创建用户
EOS账号创建不像以太坊账号,EOS账号不能自己生成,需要由EOS账号才能注册EOS账号。因此,如果想要创建EOS账号,需要找到有EOS账号的朋友帮忙注册,通过支持EOS账号的钱包就可以进行注册。

EOS主网中,账号的创建需要保存在EOS主网中,需要占用区块链生产节点(BP)的内存资源,一般为4K大小。而内存资源是有限的宝贵资源。因此账号创建是有成本的。以当前EOS主网内存资源价格0.16EOS/KB计算,需要消耗0.64EOS,按照当前6美元/EOS价格计算,内存就需要耗费3.84美元。而内存价格和EOS价格是随市场变动的,因此EOS主网账户注册价格也是变动的。账户进行转账等操作时,是没有手续费的。但是需要用到EOS主网的CPU和带宽资源。CPU就像会计的算账能力,带宽则可理解成转账的通道。这个需要通过EOS抵押才能换取。但是不会产生消耗,不用了可以赎回。

命令:
	cleos create account eosio {YOUR_ACCOUNT_NAME}   {OWNER_PUBLICKEY} {ACTIVE_PUBLICKEY}
	或
	cleos system newaccount [OPTIONS] creator name OwnerKey [ActiveKey]
eg:
	cleos create account eosio chenhao1 EOS5gdTnScL5DTVPxknPKgzfD26SBEkSyepb9Em35u7mKyQzEyq9k 			 EOS5gdTnScL5DTVPxknPKgzfD26SBEkSyepb9Em35u7mKyQzEyq9k
	返回:
	executed transaction: 6f88aebae67f7b37e06b37e20db1d807d876ff88cf19d381a6f0b961c0529017  200 bytes  406 us
	#  eosio <= eosio::newaccount     {"creator":"eosio","name":"chenhao1","owner":{"threshold":1,"keys":[{"key":"EOS5gdTnScL5DTVPxknPKgzf...

在EOS中每个账户都有两个默认权限,称为owner和active。
其中owner 表示对一个账户的所有权。只有很少的交易需要用到此权限,一般只会在修改账户权限的时候用到。建议将此权限的私钥放入冷钱包储存。此权限可以重置其他权限。
active 权限用来进行转账,为节点投票,以及其他高级别的账户修改。
简单来说,owner权限可以执行所有的操作,而active权限则可以执行除了更改owner权限对应的密钥对以外的全部操作。
EOS针对账户支持可自定义权限,以便账户的扩展性管理。

3.8关闭钱包

命令:
	cleos wallet lock --name  钱包名称
eg:
	 cleos wallet lock --name eosio.wallet
	 Locked: eosio.wallet

关于cleos命令的参数类型请参照:https://blog.youkuaiyun.com/w7849516230/article/details/80963115;https://www.jianshu.com/p/8e11fc320920

上述介绍了EOS私有链的搭建和钱包的管理功能,那么EOS是怎么进行账户间的转账的呢?我们将在下篇博文中介绍。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值