10分钟搭建最新EOS钱包节点
EOS 结构
EOS运行结构主要分为3部分:
- cleos: 客户端, 向节点与钱包请求数据. 该项为http请求协议, 可按标准使用重写方式替代, 在开发语言只需要调用接口即可.
- keosd: 钱包节点, 主要负责管理私钥, 签名等钱包行为.
- neosd: 主节点, 链端数据全部由neosd同步及存储, 而该程序会加载不同的模块, 实现不同的功能.
由上面的结构我们也就知道了, 我们搭建一个EOS节点最少需要的部分 neosd
. 但如果这样, 我们就需要开发keosd
钱包程序和cleos
客户端程序. 而这不在我们本次的教程行列内, 本次主要以最快的速度搭建可用的EOS节点
, 使用官方钱包.
解决数据同步问题
本文档时间在2020年8月1日时, EOS最新块为:134313080
, EOS出块速度约为5个块/s. 如果自己同步, 消耗大量的服务器性能不说, 还要使用大量的时间来同步.
那节点数据如何解决呢?可以使用以下方案:
- 使用EOS节点, 自己来同步, 但时间很长.
- 使用EOS公共节点解决数据共共享. 时间短.
- 使用公共API来解决数据问题. 很多区块链浏览器提供此功能. 不过一些要收费.
我们今天重要讨论的是
方法2
一、安装EOS主要程序
如果想要自己编译, 自己安装的话, 可以使用官网教程, 本文章不讨论如何编译EOS节点. 如果需要请移步:
EOS节点编译
我们使用npm安装方式.
Centos 安装使用
wget https://github.com/eosio/eos/releases/download/v2.0.1/eosio-2.0.1-1.el7.x86_64.rpm
sudo yum install ./eosio-2.0.1-1.el7.x86_64.rpm
Ubuntu 安装使用
wget https://github.com/EOSIO/eos/releases/download/v2.0.7/eosio_2.0.7-1-ubuntu-18.04_amd64.deb
sudo apt install ./eosio_1.5.2-1-ubuntu-18.04_amd64.deb
Mac OSX 安装
brew tap eosio/eosio
brew install eosio
安装辅助程序
辅助程度主要有2个:
- NGINX:代理请求EOS公共节点
- Supervisor:守护进程
Nginx安装
这里主要是EOS说明, 不使用相对麻烦的编译安装, 如果需要请稳步其他文章.
sudo yum -y install nginx
sudo systemctl enable nginx # 设置开机启动
sudo service nginx start # 启动 nginx 服
Supervosor安装
sudo yum install epel-release
sudo yum install -y supervisor
sudo systemctl enable supervisord # 开机自启动
sudo systemctl start supervisord # 启动
配置
节点配置
EOS节点最难的不在于如何配置, 而在于如何找到合适适用的节点. 而节点的变动率很高, 如何高效的处理节点其实是需要一定经验的.
我这里有一套适用于交易所的节点查找代码, 需要请陪联系.
server {
listen 5001;
server_name localhost;
location / {
client_max_body_size 1000m;
proxy_pass http://eos.greymass.com;
proxy_set_header Host $proxy_host;
}
}
重新读取nginx配置
nginx -s reload
钱包配置
我们默认将钱包放在家目录下, 在家目录下创建eos
当主要存放文件夹.
mkdir -p ~/eos/
先编辑钱包启动命令:
vim /etc/supervisord.d/keosd.ini
[program:keosd]
command=keosd -d /root/eos/eosio-wallet/ --config-dir /root/eos/eosio-wallet/
# 为了方便使用root, 建议大家按实际需求使用专用用户
user=root
stdout_logfile=/var/log/supervisor/keosd.log
redirect_stderr=true
stdout_logfile_maxbytes=500MB
钱包配置文件
# The filename (relative to data-dir) to create a unix socket for HTTP RPC; set blank to disable. (eosio::http_plugin)
# unix-socket-path = keosd.sock
# The local IP and port to listen for incoming http connections; leave blank to disable. (eosio::http_plugin)
http-server-address = 0.0.0.0:5002
# 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 =
# Configure https ECDH curve to use: secp384r1 or prime256v1 (eosio::http_plugin)
# https-ecdh-curve = secp384r1
# 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
# Maximum size in megabytes http_plugin should use for processing http requests. 503 error response when exceeded. (eosio::http_plugin)
# http-max-bytes-in-flight-mb = 500
# 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 = true
# 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 =
# Number of worker threads in http thread pool (eosio::http_plugin)
http-threads = 5
# 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 (default 900 (15 minutes)). 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 = 600
# Override default URL of http://localhost:12345 for connecting to yubihsm-connector (eosio::wallet_plugin)
# yubihsm-url =
# Enables YubiHSM support using given Authkey (eosio::wallet_plugin)
# yubihsm-authkey =
# Plugin(s) to enable, may be specified multiple times
# plugin =
此时启动supervisor的keosd服务, 可看到钱包已启动.
supervisorctl update
supervisorctl start keosd
验证
到这个时间节点与钱包均已安装完成了. 该开始验证环节了.
配置cleos快捷访问
echo 'alias c="cleos -u http://127.0.0.1:5001 --wallet-url http://127.0.0.1:5002 "
alias cw="c wallet "' >> ~/.bashrc
验证节点
请求最新节点数据:
c get info
响应体:
{
"server_version": "c173d52d",
"chain_id": "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906",
"head_block_num": 134484685,
"last_irreversible_block_num": 134484357,
"last_irreversible_block_id": "08041185241850cb4d1d4f053c681ccd32009100b5f96c75b2e452add0efd5ab",
"head_block_id": "080412cde7706a3b8a853184bfa3f4edf63008bbd2b6d9a83c0133b81229059b",
"head_block_time": "2020-08-02T16:24:49.500",
"head_block_producer": "hashfineosio",
"virtual_block_cpu_limit": 200000,
"virtual_block_net_limit": 1048576000,
"block_cpu_limit": 200000,
"block_net_limit": 1048576,
"server_version_string": "v2.0.6",
"fork_db_head_block_num": 134484685,
"fork_db_head_block_id": "080412cde7706a3b8a853184bfa3f4edf63008bbd2b6d9a83c0133b81229059b",
"server_full_version_string": "v2.0.6-c173d52da6a386f3dd0ae00c758318a064ea0165-dirty"
}
验证钱包
浏览所有钱包
cw list
响应数据:
[]
至此, 你已经有了一个全节点EOS钱包了.
常用命令
这里给一些常用的命令.
节点常用命令
获取账户信息
c get account 账户名
请求:
c get account arthureosdev
响应:
created: 2018-07-23T04:38:33.500
...
# 内容过多, 不一一展示
获取余额
命令:c get currency balance 合约地址 账户名
请求:
c get currency balance eosio.token arthureosdev
响应:
1.0000 EOS
转账户
用此命令前需要选解锁钱包
命令:c transfer 发送人账户 接收人账户
请求:
c transfer arthureosdev huobideposit "1.0000 EOS" "备注内容"
响应:
币不多了, 未实际执行, 结果非常简单, 仅成功与失败, 英文也非常简单.
其他更多命令可自行探索
钱包命令
钱包有一个参数为 -n
, 此参数非必须, 未指定时为default
, 请注意.
创建钱包
创建钱包会得到一组密码, 该密码不可自由设定, 密码会打印在控制台或文件中, 所以必须有--to-console
或--file
参数
命令: cw create [-n] 钱包名 [--file] or [--to-console]
请求:
cw create -n arthur --to-console
响应:
Creating wallet: arthur
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5KM4T47qNd4kiq8Ppv2jwW2CX33exxDvnXyTE9Fo7FUwcEpepai"
这里的PW5KM4T47qNd4kiq8Ppv2jwW2CX33exxDvnXyTE9Fo7FUwcEpepai
就是钱包密码
解锁钱包
命令: cw open [-n] 钱包名称
请求:
cw unlock -n arthur
> 请输入密码
响应:
Opened: arthur
创建新私钥
命令:cw create_key [-n] 钱包名称
请求:
cw create_key -n arthur
响应:
Created new private key with a public key of: "EOS5rTHuVHChztqmgVBTsH6e5WLBnazvK6HjEd9XDn8hrNYxxeoim"
注意:
:EOS5rTHuVHChztqmgVBTsH6e5WLBnazvK6HjEd9XDn8hrNYxxeoim
是你的公钥, 私钥需要使用另外命令才可以查看.
查看私钥
命令:cw private_keys [-n] 钱包名称
请求:
cw private_keys -n arthur
> 请输入密码
响应:
[[
"EOS5rTHuVHChztqmgVBTsH6e5WLBnazvK6HjEd9XDn8hrNYxxeoim", "5JCjTvigG72V6d6VSU5oKdHTQa9fTC22WNe7wZgyurWm1ruciJs"
]
]
结语
主要使用的大致是这些, 但其他的例如:
- 抵押
- 取消抵押
- 赎回(当前已为自动)
- 获取历史交易
等操作大同小异, 可自行查看命令行.
网友评论