私链搭建(多机多节点)
最终创建三个虚拟机,三个生产节点的私链
各节点之间通过区块服务nodeos联通,区块服务是对公网的
钱包服务keosd传输密钥时使用明文,所以只对本机提供服务
cleos通过四个参数,设置连接哪个keosd和哪个nodeos
cleos也可以直接使用nodeos提供的本地钱包服务操作钱包,但nodeos要加载钱包插件
开启服务
#BC01
./nodeos --http-server-address 0.0.0.0:8888 --p2p-listen-endpoint 0.0.0.0:9876 --enable-stale-production --producer-name eosio --plugin eosio::chain_api_plugin --plugin eosio::net_api_plugin --plugin eosio::wallet_api_plugin --plugin eosio::account_history_api_plugin 1>nodeos.log 2>&1 &
./keosd --http-server-address 127.0.0.1:8899 1>keosd.log 2>&1 &
#BC02,--p2p-peer-address指向BC01
./nodeos --http-server-address 0.0.0.0:8888 --p2p-listen-endpoint 0.0.0.0:9876 --p2p-peer-address 172.16.172.81:9876 --enable-stale-production --producer-name eosio --plugin eosio::chain_api_plugin --plugin eosio::net_api_plugin --plugin eosio::wallet_api_plugin --plugin eosio::account_history_api_plugin 1>nodeos.log 2>&1 &
./keosd --http-server-address 127.0.0.1:8899 1>keosd.log 2>&1 &
#BC03,--p2p-peer-address指向BC01
./nodeos --http-server-address 0.0.0.0:8888 --p2p-listen-endpoint 0.0.0.0:9876 --p2p-peer-address 172.16.172.81:9876 --enable-stale-production --producer-name eosio --plugin eosio::chain_api_plugin --plugin eosio::net_api_plugin --plugin eosio::wallet_api_plugin --plugin eosio::account_history_api_plugin 1>nodeos.log 2>&1 &
./keosd --http-server-address 127.0.0.1:8899 1>keosd.log 2>&1 &
创建钱包与账号
#BC01
#创建钱包、生成并导入密钥,创建账号
./cleos --wallet-port 8899 wallet create
"PW5KDZZWxtGroTQG8d1v1fiRm2FvNfE8QZzvnfZLEV8BGRPw8Tx8X"
./cleos create key
Private key: 5KPRMHBNnXLybgHFhFb7wVF9hLkRKu4aLb7s7xNaZVND8GtunT8
Public key: EOS5wfaugnegAjXPSTgaquJL51taDmqftbGFcWmvNoDKMsYzrnydX
./cleos --wallet-port 8899 wallet import -n default 5KPRMHBNnXLybgHFhFb7wVF9hLkRKu4aLb7s7xNaZVND8GtunT8
./cleos --wallet-port 8899 create account eosio token1 EOS5wfaugnegAjXPSTgaquJL51taDmqftbGFcWmvNoDKMsYzrnydX EOS5wfaugnegAjXPSTgaquJL51taDmqftbGFcWmvNoDKMsYzrnydX
./cleos --wallet-port 8899 create account eosio patient1 EOS5wfaugnegAjXPSTgaquJL51taDmqftbGFcWmvNoDKMsYzrnydX EOS5wfaugnegAjXPSTgaquJL51taDmqftbGFcWmvNoDKMsYzrnydX
#BC02
#创建钱包、生成并导入密钥,创建账号
./cleos --wallet-port 8899 wallet create
"PW5JJv6uxu8FcxT3zRbzVuxDquKFeeGQJj6f2kguXqfApSx9Lyg5k"
./cleos create key
Private key: 5K2G75aBEqBWRZdJZcFcb7gCjezcxfC8hFMUk4XVPmGj8JmqSCA
Public key: EOS5baefwj8ALkjjo9fZsjtDagYecd3VYVjwaMuVN55e44ViJQXve
./cleos --wallet-port 8899 wallet import -n default 5K2G75aBEqBWRZdJZcFcb7gCjezcxfC8hFMUk4XVPmGj8JmqSCA
./cleos --wallet-port 8899 create account eosio patient2 EOS5baefwj8ALkjjo9fZsjtDagYecd3VYVjwaMuVN55e44ViJQXve EOS5baefwj8ALkjjo9fZsjtDagYecd3VYVjwaMuVN55e44ViJQXve
#BC03
#创建钱包、生成并导入密钥,创建账号
./cleos --wallet-port 8899 wallet create
"PW5JWH5MHmrZhAgbmmmMNEHj4hdG2HxueCX8amKaNxX5o1kycLkmf"
./cleos create key
Private key: 5JM4jmDJoBdjTksz5KcBkCqrZxB3hi11GCPohbMg67r2pZu1P1E
Public key: EOS5MwWYV4dDVyrY3gpiZRfPpvX2ADWA2C8n9TT4D1Qho7BHHSLKh
./cleos --wallet-port 8899 wallet import -n default 5JM4jmDJoBdjTksz5KcBkCqrZxB3hi11GCPohbMg67r2pZu1P1E
./cleos --wallet-port 8899 create account eosio patient3 EOS5MwWYV4dDVyrY3gpiZRfPpvX2ADWA2C8n9TT4D1Qho7BHHSLKh EOS5MwWYV4dDVyrY3gpiZRfPpvX2ADWA2C8n9TT4D1Qho7BHHSLKh
加载智能合约,发币并转账
#BC01
./cleos --wallet-port 8899 set contract token1 ../contracts/eosio.token -p token1
./cleos --wallet-port 8899 push action token1 create '{"issuer":"token1", "maximum_supply":"10000.00 CT", "can_freeze":0, "can_recall":0, "can_whitelist":0}' -p token1
./cleos --wallet-port 8899 push action token1 issue '["patient1", "100.00 CT", "memo"]' -p token1
./cleos --wallet-port 8899 push action token1 transfer '["patient1", "patient2", "5.00 CT", "Just a test" ]' -p patient1
#BC02
./cleos --wallet-port 8899 push action token1 transfer '["patient2", "patient3", "2.00 CT", "Just a test" ]' -p patient2
#BC03
./cleos --wallet-port 8899 push action token1 transfer '["patient3", "patient1", "1.00 CT", "Just a test" ]' -p patient3
查询结果
#任意节点
./cleos --wallet-port 8899 get table token1 token1 accounts
{
"rows": [{
"balance": "0.00 CT",
"frozen": 0,
"whitelist": 1
}
],
"more": false
}
./cleos --wallet-port 8899 get table token1 patient1 accounts
{
"rows": [{
"balance": "96.00 CT",
"frozen": 0,
"whitelist": 1
}
],
"more": false
}
./cleos --wallet-port 8899 get table token1 patient2 accounts
{
"rows": [{
"balance": "3.00 CT",
"frozen": 0,
"whitelist": 1
}
],
"more": false
}
./cleos --wallet-port 8899 get table token1 patient3 accounts
{
"rows": [{
"balance": "1.00 CT",
"frozen": 0,
"whitelist": 1
}
],
"more": false
}
最后更新于