10分鐘搭建最新EOS錢包節(jié)點(diǎn)
EOS 結(jié)構(gòu)
EOS運(yùn)行結(jié)構(gòu)主要分為3部分:
- cleos: 客戶端, 向節(jié)點(diǎn)與錢包請(qǐng)求數(shù)據(jù). 該項(xiàng)為http請(qǐng)求協(xié)議, 可按標(biāo)準(zhǔn)使用重寫方式替代, 在開發(fā)語言只需要調(diào)用接口即可.
- keosd: 錢包節(jié)點(diǎn), 主要負(fù)責(zé)管理私鑰, 簽名等錢包行為.
- neosd: 主節(jié)點(diǎn), 鏈端數(shù)據(jù)全部由neosd同步及存儲(chǔ), 而該程序會(huì)加載不同的模塊, 實(shí)現(xiàn)不同的功能.
由上面的結(jié)構(gòu)我們也就知道了, 我們搭建一個(gè)EOS節(jié)點(diǎn)最少需要的部分 neosd
. 但如果這樣, 我們就需要開發(fā)keosd
錢包程序和cleos
客戶端程序. 而這不在我們本次的教程行列內(nèi), 本次主要以最快的速度搭建可用的EOS節(jié)點(diǎn)
, 使用官方錢包.
解決數(shù)據(jù)同步問題
本文檔時(shí)間在2020年8月1日時(shí), EOS最新塊為:134313080
, EOS出塊速度約為5個(gè)塊/s. 如果自己同步, 消耗大量的服務(wù)器性能不說, 還要使用大量的時(shí)間來同步.
那節(jié)點(diǎn)數(shù)據(jù)如何解決呢?可以使用以下方案:
- 使用EOS節(jié)點(diǎn), 自己來同步, 但時(shí)間很長(zhǎng).
- 使用EOS公共節(jié)點(diǎn)解決數(shù)據(jù)共共享. 時(shí)間短.
- 使用公共API來解決數(shù)據(jù)問題. 很多區(qū)塊鏈瀏覽器提供此功能. 不過一些要收費(fèi).
我們今天重要討論的是
方法2
一损搬、安裝EOS主要程序
如果想要自己編譯, 自己安裝的話, 可以使用官網(wǎng)教程, 本文章不討論如何編譯EOS節(jié)點(diǎn). 如果需要請(qǐng)移步:
EOS節(jié)點(diǎn)編譯
我們使用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個(gè):
- NGINX:代理請(qǐng)求EOS公共節(jié)點(diǎn)
- Supervisor:守護(hù)進(jìn)程
Nginx安裝
這里主要是EOS說明, 不使用相對(duì)麻煩的編譯安裝, 如果需要請(qǐng)穩(wěn)步其他文章.
sudo yum -y install nginx
sudo systemctl enable nginx # 設(shè)置開機(jī)啟動(dòng)
sudo service nginx start # 啟動(dòng) nginx 服
Supervosor安裝
sudo yum install epel-release
sudo yum install -y supervisor
sudo systemctl enable supervisord # 開機(jī)自啟動(dòng)
sudo systemctl start supervisord # 啟動(dòng)
配置
節(jié)點(diǎn)配置
EOS節(jié)點(diǎn)最難的不在于如何配置, 而在于如何找到合適適用的節(jié)點(diǎn). 而節(jié)點(diǎn)的變動(dòng)率很高, 如何高效的處理節(jié)點(diǎn)其實(shí)是需要一定經(jīng)驗(yàn)的.
我這里有一套適用于交易所的節(jié)點(diǎn)查找代碼, 需要請(qǐng)陪聯(lián)系.
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
錢包配置
我們默認(rèn)將錢包放在家目錄下, 在家目錄下創(chuàng)建eos
當(dāng)主要存放文件夾.
mkdir -p ~/eos/
先編輯錢包啟動(dòng)命令:
vim /etc/supervisord.d/keosd.ini
[program:keosd]
command=keosd -d /root/eos/eosio-wallet/ --config-dir /root/eos/eosio-wallet/
# 為了方便使用root, 建議大家按實(shí)際需求使用專用用戶
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 =
此時(shí)啟動(dòng)supervisor的keosd服務(wù), 可看到錢包已啟動(dòng).
supervisorctl update
supervisorctl start keosd
驗(yàn)證
到這個(gè)時(shí)間節(jié)點(diǎn)與錢包均已安裝完成了. 該開始驗(yàn)證環(huán)節(jié)了.
配置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
驗(yàn)證節(jié)點(diǎn)
請(qǐng)求最新節(jié)點(diǎn)數(shù)據(jù):
c get info
響應(yīng)體:
{
"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"
}
驗(yàn)證錢包
瀏覽所有錢包
cw list
響應(yīng)數(shù)據(jù):
[]
至此, 你已經(jīng)有了一個(gè)全節(jié)點(diǎn)EOS錢包了.
常用命令
這里給一些常用的命令.
節(jié)點(diǎn)常用命令
獲取賬戶信息
c get account 賬戶名
請(qǐng)求:
c get account arthureosdev
響應(yīng):
created: 2018-07-23T04:38:33.500
...
# 內(nèi)容過多, 不一一展示
獲取余額
命令:c get currency balance 合約地址 賬戶名
請(qǐng)求:
c get currency balance eosio.token arthureosdev
響應(yīng):
1.0000 EOS
轉(zhuǎn)賬戶
用此命令前需要選解鎖錢包
命令:c transfer 發(fā)送人賬戶 接收人賬戶
請(qǐng)求:
c transfer arthureosdev huobideposit "1.0000 EOS" "備注內(nèi)容"
響應(yīng):
幣不多了, 未實(shí)際執(zhí)行, 結(jié)果非常簡(jiǎn)單, 僅成功與失敗, 英文也非常簡(jiǎn)單.
其他更多命令可自行探索
錢包命令
錢包有一個(gè)參數(shù)為 -n
, 此參數(shù)非必須, 未指定時(shí)為default
, 請(qǐng)注意.
創(chuàng)建錢包
創(chuàng)建錢包會(huì)得到一組密碼, 該密碼不可自由設(shè)定, 密碼會(huì)打印在控制臺(tái)或文件中, 所以必須有--to-console
或--file
參數(shù)
命令: cw create [-n] 錢包名 [--file] or [--to-console]
請(qǐng)求:
cw create -n arthur --to-console
響應(yīng):
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] 錢包名稱
請(qǐng)求:
cw unlock -n arthur
> 請(qǐng)輸入密碼
響應(yīng):
Opened: arthur
創(chuàng)建新私鑰
命令:cw create_key [-n] 錢包名稱
請(qǐng)求:
cw create_key -n arthur
響應(yīng):
Created new private key with a public key of: "EOS5rTHuVHChztqmgVBTsH6e5WLBnazvK6HjEd9XDn8hrNYxxeoim"
注意:
:EOS5rTHuVHChztqmgVBTsH6e5WLBnazvK6HjEd9XDn8hrNYxxeoim
是你的公鑰, 私鑰需要使用另外命令才可以查看.
查看私鑰
命令:cw private_keys [-n] 錢包名稱
請(qǐng)求:
cw private_keys -n arthur
> 請(qǐng)輸入密碼
響應(yīng):
[[
"EOS5rTHuVHChztqmgVBTsH6e5WLBnazvK6HjEd9XDn8hrNYxxeoim", "5JCjTvigG72V6d6VSU5oKdHTQa9fTC22WNe7wZgyurWm1ruciJs"
]
]
結(jié)語
主要使用的大致是這些, 但其他的例如:
- 抵押
- 取消抵押
- 贖回(當(dāng)前已為自動(dòng))
- 獲取歷史交易
等操作大同小異, 可自行查看命令行.