(注:1.本文操作前提是EOS(最新版v1.7.3)代码编译正常(参加本人另一篇编译文章),有一定EOS基础 ; 2. 开发环境 VMware WS 12+ ubuntu 16.04 ;3.以下操作需要根据具体情况 变通处理!!)
1. eosio账户公钥写死在代码中, 在代码根目录 CMakeList.txt里面,找到 EOSIO_ROOT_KEY,改为自己创建的公钥。并把新的密钥对 要在 config.ini文件中保存,见文件中 “signature-provider = 。。。”。
2.编译,安装,参加本人另一篇EOS编译文章。
1.建议在 nodeos 程序运行目录创建 config文件夹,保存配置文件;同时创建 data文件夹 ,保存区块文件.
2.搭建4个独立IP 的 节点(同一局域网),命名为:eosio, node1,node2,node3。所有节点的 genesis.json文件一样,否则不是一个网络,不能通信。
3.genesis.json 文件内容,如下:
{
"initial_timestamp": "2018-06-08T08:08:08.888",
"initial_key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", #####必须是 eosio 节点 的 公钥
"initial_configuration": {
"max_block_net_usage": 1048576,
"target_block_net_usage_pct": 1000,
"max_transaction_net_usage": 524288,
"base_per_transaction_net_usage": 12,
"net_usage_leeway": 500,
"context_free_discount_net_usage_num": 20,
"context_free_discount_net_usage_den": 100,
"max_block_cpu_usage": 200000,
"target_block_cpu_usage_pct": 1000,
"max_transaction_cpu_usage": 150000,
"min_transaction_cpu_usage": 100,
"max_transaction_lifetime": 3600,
"deferred_trx_expiration_window": 600,
"max_transaction_delay": 3888000,
"max_inline_action_size": 4096,
"max_inline_action_depth": 4,
"max_authority_depth": 6
}
}
4.eosio 节点的 config.ini文件
block-log-dir = "blocks"
shared-memory-size-mb = 1024
http-server-address = 127.0.0.1:8888
access-control-allow-credentials = false
p2p-listen-endpoint = 0.0.0.0:9876
p2p-peer-address = 192.168.8.109:9876
p2p-peer-address = 192.168.8.52:9876
p2p-peer-address = 192.168.8.216:9876
agent-name = "SQU chain"
allowed-connection = any
max-clients = 25
connection-cleanup-period = 30
network-version-match = 0
sync-fetch-span = 100
max-implicit-request = 1500
enable-stale-production = true ## 只是eosio节点 为true
max-transaction-time = 1000
required-participation = 33
producer-name = eosio ## 注意节点账户名称,下面是 账户的 keys
signature-provider =
EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV=KEY:5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
wallet-dir = "."
unlock-timeout = 90000
plugin = eosio::chain_api_plugin
plugin = eosio::chain_plugin
plugin = eosio::producer_plugin
plugin = eosio::http_plugin
plugin = eosio::history_api_plugin
5.node1,node2,node3 节点的 config.ini 文件类似,只需修改备注的地方
block-log-dir = "blocks"
shared-memory-size-mb = 1024
http-server-address = 127.0.0.1:8888
access-control-allow-credentials = false
p2p-listen-endpoint = 0.0.0.0:9876
p2p-peer-address = 192.168.8.215:9876 ##其他节点的 p2p 地址及端口,不要填写本节点的IP!
p2p-peer-address = 192.168.8.216:9876
p2p-peer-address = 192.168.8.52:9876
agent-name = "SQU chain"
allowed-connection = any
max-clients = 25
connection-cleanup-period = 30
network-version-match = 0
sync-fetch-span = 100
max-implicit-request = 1500
max-transaction-time = 30
required-participation = 33
producer-name = node1 ## 设置本节点账户名称,下面是 该账户的 keys ,根据自己的去修改!!
signature-provider = EOS6AzQmSAXHH8Mn7pi6B7zZ9UcVfmS5tcVS681bjz5ZvkGPXzGto=KEY:5HxfD1WGTBeVpMvobBDvpd9qLGn8VhLds14GwRaK6zq51XgNvF9
txn-reference-block-lag = 0
wallet-dir = "."
unlock-timeout = 90000
plugin = eosio::chain_api_plugin
plugin = eosio::chain_plugin
plugin = eosio::producer_plugin
plugin = eosio::http_plugin
plugin = eosio::history_api_plugin
三 .创建与发行代币
1.启动四个节点nodeos程序
(把 config.ini, genesis.json文件放到 config 目录, 区块文件放在 data目录)
命令如下:
nodeos --data-dir ./data --config-dir ./config --genesis-json ./config/genesis.json
2.在 eosio 节点上创建钱包 squwallet ,并导入eosio账户私钥
cleos wallet import -n squwallet --private-key 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
3.创建发布token的帐号eosio.token (需自己去创建 key,并把私钥导入到钱包)
cleos create account eosio eosio.token EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
4.发布eosio.token合约 (在eosio.contracts 代码编译后的 build/下面执行)
gavin@ubuntu:~/eosio.contracts/build$ pwd (当前目录)
/home/gavin/eosio.contracts/build
gavin@ubuntu:~/eosio.contracts/build$ ls contracts (子目录)
CMakeCache.txt CMakeFiles cmake_install.cmake eosio.bios eosio.msig eosio.system eosio.token eosio.wrap Makefile
gavin@ubuntu:~/eosio.contracts/build$ ls contracts/eosio.token/
CMakeFiles cmake_install.cmake eosio.token.abi eosio.token.wasm Makefile
gavin@ubuntu:~/eosio.contracts/build$
在build目录下执行 cleos set contract eosio.token ./contracts/eosio.token --abi eosio.token.abi -p :
gavin@ubuntu:~/eosio.contracts/build$ cleos set contract eosio.token ./contracts/eosio.token --abi eosio.token.abi -p eosio.token@active
Reading WASM from /home/gavin/eosio.contracts/build/contracts/eosio.token/eosio.token.wasm...
Publishing contract...
executed transaction: 7bd751e63adfbdb639023d63e3702830db4293b479b051bfc6ef8d8fc5ee1eb9 9512 bytes 1336 us
# eosio <= eosio::setcode {"account":"eosio.token","vmtype":0,"vmversion":0,"code":"0061736d0100000001b1011d60037f7e7f0060047f...
# eosio <= eosio::setabi {"account":"eosio.token","abi":"0e656f73696f3a3a6162692f312e310008076163636f756e7400010762616c616e63...
warning: transaction executed locally, but may not be confirmed by the network yet ]
gavin@ubuntu:~/eosio.contracts/build$
gavin@ubuntu:~/eosio.contracts/build$
5.创建代币
gavin@ubuntu:~$ cleos push action eosio.token create '[ "eosio", "1000000000.0000 SYS"]' -p eosio.token@active
executed transaction: 353ba8ee7deb942db70c3029ed464d40de3b75aa312de2c99ec9f3dfca8c5391 120 bytes 195 us
# eosio.token <= eosio.token::create {"issuer":"eosio","maximum_supply":"1000000000.0000 SYS"}
warning: transaction executed locally, but may not be confirmed by the network yet ]
gavin@ubuntu:~$
6.发行代币
gavin@ubuntu:~$ cleos push action eosio.token issue '["eosio","1000000000.0000 SYS","issue"]' -p eosio@active
executed transaction: f778aa8a2ee27a7a9e0bc53515e47cf6787149bd6dddef7947ffa0e0e7960269 128 bytes 202 us
# eosio.token <= eosio.token::issue {"to":"eosio","quantity":"1000000000.0000 SYS","memo":"issue"}
warning: transaction executed locally, but may not be confirmed by the network yet ]
gavin@ubuntu:~$
用命令查看 eosio 账户代币:
gavin@ubuntu:~$ cleos get currency balance eosio.token eosio SYS
1000000000.0000 SYS
gavin@ubuntu:~$
四 .发布 eosio.system合约
1.创建下面系统账户(共用一套公钥,实际情况 最好使用不同key,并把key导入到钱包)
cleos create account eosio eosio.bpay EOS5jh1BaxfnQhYwJqg7P2CYpyNp2gw9mdctprVpnFCKUqBJU3zEt EOS5jh1BaxfnQhYwJqg7P2CYpyNp2gw9mdctprVpnFCKUqBJU3zEt
cleos create account eosio eosio.msig EOS5jh1BaxfnQhYwJqg7P2CYpyNp2gw9mdctprVpnFCKUqBJU3zEt EOS5jh1BaxfnQhYwJqg7P2CYpyNp2gw9mdctprVpnFCKUqBJU3zEt
cleos create account eosio eosio.name EOS5jh1BaxfnQhYwJqg7P2CYpyNp2gw9mdctprVpnFCKUqBJU3zEt EOS5jh1BaxfnQhYwJqg7P2CYpyNp2gw9mdctprVpnFCKUqBJU3zEt
cleos create account eosio eosio.names EOS5jh1BaxfnQhYwJqg7P2CYpyNp2gw9mdctprVpnFCKUqBJU3zEt EOS5jh1BaxfnQhYwJqg7P2CYpyNp2gw9mdctprVpnFCKUqBJU3zEt
cleos create account eosio eosio.ram EOS5jh1BaxfnQhYwJqg7P2CYpyNp2gw9mdctprVpnFCKUqBJU3zEt EOS5jh1BaxfnQhYwJqg7P2CYpyNp2gw9mdctprVpnFCKUqBJU3zEt
cleos create account eosio eosio.ramfee EOS5jh1BaxfnQhYwJqg7P2CYpyNp2gw9mdctprVpnFCKUqBJU3zEt EOS5jh1BaxfnQhYwJqg7P2CYpyNp2gw9mdctprVpnFCKUqBJU3zEt
cleos create account eosio eosio.saving EOS5jh1BaxfnQhYwJqg7P2CYpyNp2gw9mdctprVpnFCKUqBJU3zEt EOS5jh1BaxfnQhYwJqg7P2CYpyNp2gw9mdctprVpnFCKUqBJU3zEt
cleos create account eosio eosio.stake EOS5jh1BaxfnQhYwJqg7P2CYpyNp2gw9mdctprVpnFCKUqBJU3zEt EOS5jh1BaxfnQhYwJqg7P2CYpyNp2gw9mdctprVpnFCKUqBJU3zEt
cleos create account eosio eosio.upay EOS5jh1BaxfnQhYwJqg7P2CYpyNp2gw9mdctprVpnFCKUqBJU3zEt EOS5jh1BaxfnQhYwJqg7P2CYpyNp2gw9mdctprVpnFCKUqBJU3zEt
2.设置eosio.msig合约 (同样在eosio.contracts /build目录下运行)
msig合约支持并简化了权限级别的定义和管理以及执行多重签名操作。
cleos set contract eosio.msig ./contracts/eosio.msig/
3.部署eosio.system合约(必须先执行上面的 “创建下面系统账户”)
该合约为几乎所有基于令牌的操作行为提供了操作。在安装系统合同之前,操作是独立于会计完成的。
一旦系统合同启用,行动现在对他们有一个经济因素。资源(cpu,网络,内存)必须付费。同样,必须支付新帐户。
系统合同使得令牌能够被放置和不被冻结,被购买的资源,可能的生产者被注册并且随后被投票,生产者奖励被要求,被设置 的特权和限制等等。
cleos set contract eosio ./contracts/eosio.system/
新版EOS system合约,还必须执行下面命令初始化!
gavin@ubuntu:~/eosio.contracts/build$ cleos push action eosio init '[0, "4,SYS"]' -p eosio@active
executed transaction: dc6e2008c21b3b6fdcb78fa236c3ff94e7dcf55723e625115ad1457799ebdb24 104 bytes 409 us
# eosio <= eosio::init {"version":0,"core":"4,SYS"}
# eosio.token <= eosio.token::open {"owner":"eosio.rex","symbol":"4,SYS","ram_payer":"eosio"}
warning: transaction executed locally, but may not be confirmed by the network yet ]
gavin@ubuntu:~/eosio.contracts/build$
4.在安装eosio.system合同后,我们希望尽快将eosio.msig设置为特权帐户,以便它可以代表eosio帐户进行授权。很快eosio将辞职,eosio.prods将接管。
使eosio.msig成为一个特权帐户。我们使用以下方法使eosio.msig有特权。
cleos push action eosio setpriv '["eosio.msig", 1]' -p eosio@active
五 .注册BP及投票
1.用下面这个命令创建投票账户:
部署了eosio.system合约之后,cleos create account这个命令就不能创建账户了。
为 node1,node2,node3 准备不同的 key, 并导入钱包。 然后创建各个出块节点的 账户:node1,node2,node3。
cleos system newaccount eosio node1 EOS6AzQmSAXHH8Mn7pi6B7zZ9UcVfmS5tcVS681bjz5ZvkGPXzGto EOS6AzQmSAXHH8Mn7pi6B7zZ9UcVfmS5tcVS681bjz5ZvkGPXzGto --stake-net '50.00 SWC' --stake-cpu '50.00 SWC' --buy-ram-kbytes 8
cleos system newaccount eosio node2 EOS5VgmxPRhvsTChoxc9b1NT6zFNhLVLfPpGcjWJUvmoke8dMVeLh EOS5VgmxPRhvsTChoxc9b1NT6zFNhLVLfPpGcjWJUvmoke8dMVeLh --stake-net '50.00 SWC' --stake-cpu '50.00 SWC' --buy-ram-kbytes 8
cleos system newaccount eosio node3 EOS7fEc1C6A8QHrK6kjFFFUmGrAmQoyivbrYaAdspKzA6io1gi5ax EOS7fEc1C6A8QHrK6kjFFFUmGrAmQoyivbrYaAdspKzA6io1gi5ax --stake-net '50.00 SWC' --stake-cpu '50.00 SWC' --buy-ram-kbytes 8
2.将所有需要出块的节点(配置文件中 producer-name = nodex)注册成bp
cleos system regproducer node1 EOS6AzQmSAXHH8Mn7pi6B7zZ9UcVfmS5tcVS681bjz5ZvkGPXzGto http://http-server-address:8888
cleos system regproducer node2 EOS5VgmxPRhvsTChoxc9b1NT6zFNhLVLfPpGcjWJUvmoke8dMVeLh http://http-server-address:8888
cleos system regproducer node3 EOS7fEc1C6A8QHrK6kjFFFUmGrAmQoyivbrYaAdspKzA6io1gi5ax http://http-server-address:8888
3.给创建的账户转账
cleos push action eosio.token transfer '["eosio", "node1","100000000.0000 SYS","vote"]' -p eosio
cleos push action eosio.token transfer '["eosio", "node2","100000000.0000 SYS","vote"]' -p eosio
cleos push action eosio.token transfer '["eosio", "node3","100000000.0000 SYS","vote"]' -p eosio
4.锁定代币
cleos system delegatebw node1 node1 '25000000.0000 SYS' '25000000.0000 SYS'
cleos system delegatebw node2 node2 '25000000.0000 SYS' '25000000.0000 SYS'
cleos system delegatebw node3 node3 '25000000.0000 SYS' '25000000.0000 SYS'
5.给出块节点投票
给 节点投票如下
cleos system voteproducer prods node1 node1 node2 node3
cleos system voteproducer prods node2 node1 node2 node3
cleos system voteproducer prods node3 node1 node2 node3
注意 :发行的tonken总量为10亿,按照要求需要至少15%的投票主网才算成功,也即1.5亿的token投票,才能轮流出块,否则还是eosio节点继续出块。
投票后,过一段时间,可以看到 节点node1 node2 node3 轮流出块。eosio节点将停止出块, 不能再给 eosio节点投票出块, eosio节点在此完成使命!