FILEEM

POWER OF DREAM

EOS私链搭建中间的经验与踩坑分享(基于V1.8.5)

此教程基于EOSV1.8.5编写。因为墙的原因,要么用内存大于8G的ubuntu 16.04+海外服务器,要么请自备梯子开全局模式。

教程使用win10子系统ubuntu 18.04和GCP ubuntu 18.04测试,结果一致。
root账户,用其他账户的请自行加sudo。

part1:编译节点和启动节点

  1. fork代码库:
git clone https://github.com/EOSIO/eos --recursive
  1. 切换到V1.8.5
cd eos
git checkout v1.8.5

  1. 执行编译
~/eos/scripts/eosio_build.sh -s EOS

编译过程中,会提示安装依赖,y确定即可,安装依赖要看网速,所以被墙了就搞不成。编译时间比较长,看机器性能。完成以后提示:

《EOS私链搭建中间的经验与踩坑分享(基于V1.8.5)》

  1. 为了开发智能合约,还需要执行:
cd ~/eos/build

make install
  1. 使用编译成功后给出的安装脚本进行EOSIO安装:
 ~/eos/scripts/eosio_install.sh

成功后提示:
《EOS私链搭建中间的经验与踩坑分享(基于V1.8.5)》

  1. 首次运行节点并退出,配置config.ini和genesis.json。

节点文件目录在上一步中已经给出,运行一下节点:

~/eosio/1.8/bin

节点应该会卡在这一步:
《EOS私链搭建中间的经验与踩坑分享(基于V1.8.5)》

正常的,因为没有配置config.ini文件。ctrl+C退出。

linux的config.ini文件在~/.local/share/eosio/nodeos/confignano ~/.local/share/eosio/nodeos/config/config.ini编辑。
启动节点前,需要修改的有以下参数,nano中使用ctrl+w进行搜索:

#设置全节点,同步所有数据
filter-on = *
#为了存全节点数据,将数据库存储加大,默认是1024
chain-state-db-size-mb = 10240
#将私链设置为区块打包节点
enable-stale-production = true
#一开始默认的打包区块的账户是eosio
producer-name = eosio
#换成eosio的公私钥对,用于出块签名,如何获取公私钥对将在钱包使用中介绍
signature-provider = <public key>=KEY:<private key> 
#开启如下的插件,方便体验链上的功能
plugin = eosio::producer_plugin
#plugin = eosio::wallet_api_plugin
plugin = eosio::chain_api_plugin
plugin = eosio::chain_plugin
plugin = eosio::http_plugin
plugin = eosio::history_api_plugin
plugin = eosio::history_plugin

使用ctrl+o保存,ctrl+x退出nano。

新建genesis.json文件:nano ~/.local/share/eosio/nodeos/config/genesis.json
内容如下,请自行修改:

{
        "initial_timestamp": "2019-11-06T11:18:08.888",
        "initial_key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
        "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
        }
}

使用ctrl+o保存,ctrl+x退出nano。

  1. 启动节点

每次用节点如果要~/eosio/1.8/bin/nodeos,客户端要~/eosio/1.8/bin/cleos就会很麻烦,所以我们设置一下环境变量,以后直接nodeos和cleos就可以了。

用nano打开.bashrc设置环境变量:

nano ~/.bashrc

在文件末尾添加:

#set eosio path
export EOSIO_PATH=~/eosio/1.8/bin
export PATH=$EOSIO_PATH:$PATH

这里的PATH是v1.8.5的,根据你的版本修改。
添加好以后ctrl+O enter ctrl+X保存退出。
然后执行:

source ~/.bashrc

让环境变量生效。

因为节点需要一致处于打开状态,所以我们新建一个screen来运行它:screen -S node,然后执行:

~/eosio/1.8/bin/nodeos

成功的话,会像下面这样半秒一个产生块:

《EOS私链搭建中间的经验与踩坑分享(基于V1.8.5)》

ctrl+a d 切出screen node,此时screen在后台运行,要切回去的时候使用screen -r node

  1. 此时使用~/eosio/1.8/bin/cleos get info会返回区块链实时信息。
root@DESKTOP:~# ~/eosio/1.8/bin/cleos get info
{
  "server_version": "a2317d38",
  "chain_id": "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f",
  "head_block_num": 8119,
  "last_irreversible_block_num": 8118,
  "last_irreversible_block_id": "00001fb6f74428fa081a78681d01a29c3d9064a6943c708f535ebff8c9197f79",
  "head_block_id": "00001fb780a1e0a01a5e1718f837dc618b8bec7580f078493aa262c227b96ce8",
  "head_block_time": "2019-11-06T12:24:27.500",
  "head_block_producer": "eosio",
  "virtual_block_cpu_limit": 200000000,
  "virtual_block_net_limit": 1048576000,
  "block_cpu_limit": 199900,
  "block_net_limit": 1048576,
  "server_version_string": "v1.8.5-dirty",
  "fork_db_head_block_num": 8119,
  "fork_db_head_block_id": "00001fb780a1e0a01a5e1718f837dc618b8bec7580f078493aa262c227b96ce8"
}

part2:钱包基本操作

cleos的很多操作都会提示ERROR: Either indicate a file using "--file" or pass "--to-console",这是让你在命令中加上参数”–file”将密码生成一个文件,还是”–to-console”打印到终端。

  1. 创建钱包cleos wallet create -n <name> --to-console
    创建一个名为test的钱包
root@taiwan:~# cleos wallet create -n test  --to-console
Creating wallet: test
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5KA6rC3BqtVMP1hBJrfGpYY8iZURwUscakvtdSMwYdVjECWHKQh"

"PW5KA6rC3BqtVMP1hBJrfGpYY8iZURwUscakvtdSMwYdVjECWHKQh"是钱包的密码,解锁时需要使用

  1. 万一上锁了进行钱包解锁cleos wallet unlock -n <name> --password <pass>
root@taiwan:~# cleos wallet unlock -n test --password PW5KA6rC3BqtVMP1hBJrfGpYY8iZURwUscakvtdSMwYdVjECWHKQh
Unlocked: test
  1. 创建公私密钥对并塞入钱包cleos wallet create_key -n <name>
root@taiwan:~# cleos wallet create_key -n test
Created new private key with a public key of: "EOS6bB9kncdTADS6a55Zm1CpmDn2iSM5R1QkPhR2xLBwxvm46SMeH"

再执行一次,两对用于之后注册账户。

  1. 查看钱包中的密钥对用cleos wallet private_keys -n <name>
    需要钱包解锁并输入钱包密码。
root@taiwan:~# cleos  wallet private_keys -n test
password: [[
    "EOS6bB9kncdTADS6a55Zm1CpmDn2iSM5R1QkPhR2xLBwxvm46SMeH",
    "5Jk5NJdTVKyjKyNcNffwVAnUBPBZXFgYS2M5pqATpoU9qe8t3ei"
  ],[
    "EOS76pGw5oQDZbGTg3fW1Vu7jZpLNHNnicvcHBeCwYG4Ee3yoKvAC",
    "5KY83mheEKpKiCkUAGYBksbVy2grMw3McW97cPzQUi8NSnKDdkG"
  ]
]
  1. 导入eosio的私钥,用cleos wallet import -n <wallet name> --private-key <private key>来进行钱包导入
    创建账户等操作需要导入eosio系统账户的私钥,有其它爱好者写的教程里面说会自动导入到default钱包,我倒是没有发现,此例中,我们导入genesis.json中”initial_key”: “EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV”的私钥,也就是config.ini中系统生成的signature-provider出块签名。是的,我也没想到这个私钥居然可以,猜想是因为initial_key的原因,等了解深入了再补充。
root@taiwan:~# cleos wallet import -n test --private-key 5KQwrPbwdL6PhX......SQZ1JiwsST4cqQzDeyXtP79zkvFD3
imported private key for: EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
  1. 创建账户用 cleos create account
    这里用默认账户eosio作为账号创建人,账户公钥和活跃公钥用test钱包中之前导入的两个,账户密钥的作用大概就只是修改活跃密钥,转账等任何交易操作都需要活跃权限密钥。
root@taiwan:~# cleos create account eosio test EOS6bB9kncdTADS6a55Zm1CpmDn2iSM5R1QkPhR2xLBwxvm46SMeH EOS76pGw5oQDZbGTg3fW1Vu7jZpLNHNnicvcHBeCwYG4Ee3yoKvAC
executed transaction: 7d28df42572f7b16a8f5dfeacb960d670aeeb0439e280fae5a1e1a878efd9c7f  200 bytes  208 us
#         eosio <= eosio::newaccount            {"creator":"eosio","name":"test","owner":{"threshold":1,"keys":[{"key":"EOS6bB9kncdTADS6a55Zm1CpmDn...
warning: transaction executed locally, but may not be confirmed by the network yet         ]

warning是提示你交易已发送,但现在可能还没有被区块链打包。如果想要验证交易是否成功,使用cleos get account test可以查看区块链上是否有test这个账户。

part3:私链激活和部署合约

  1. 部署eosio.bios系统合约,部署账户为eosio。

使用cleos set contract eosio contracts/eosio.bios -p eosio部署智能合约,执行时可能会报错:

root@taiwan:~# cleos set contract eosio contracts/eosio.bios -p eosio
error 2019-11-07T11:29:32.082 cleos     main.cpp:3941                 main                 ] Failed with error: unspecified (0)
Unable to resolve path 'contracts/eosio.bios'

这是由于clone的项目代码中不自带eosio.contracts或是你没有切换到eos源代码目录中执行的原因,后一种好办,切换到~/eos目录就行,前一种的话,需要git clone https://github.com/EOSIO/eosio.contracts --branch v1.8.0 --single-branch来拉取源码,然后执行~/eosio.contracts/build.sh进行编译,编译完以后会生成build目录,将eosio.contracts/build/contracts 拷贝到~/eos目录就可以了。

再次执行cleos set contract eosio contracts/eosio.bios -p eosio,可能还是会报错:

root@taiwan:~# cleos set contract eosio ~/eos/contracts/eosio.bios -p eosio
Reading WASM from /root/eos/contracts/eosio.bios/eosio.bios.wasm...
Publishing contract...
Error 3070000: WASM Exception
Error Details:
env.is_feature_activated unresolveable

这是由于feature未激活的原因,首先需要将plugin = eosio::producer_api_plugin添加到config.ini末尾,然后重启节点。

apt  install jq
curl -X POST http://127.0.0.1:8888/v1/producer/get_supported_protocol_features -d '{}' | jq

会打印出一长段信息,复制 PREACTIVATE_FEATURE: “feature_digest”:”0ec7e080177b2c02b278d5088611686b49d739925a92d9bfcacd7fc6b74053bd”字段,替换以下命令中的相关字段然后执行:

curl -X POST http://127.0.0.1:8888/v1/producer/schedule_protocol_feature_activations -d '{"protocol_features_to_activate": ["0ec7e080177b2c02b278d5088611686b49d739925a92d9bfcacd7fc6b74053bd"]}' | jq

结果显示{ "result": "ok" }即激活成功。

再次执行cleos set contract eosio contracts/eosio.bios -p eosio,注意钱包需要是解锁状态,并且导入了eosio的私钥,怎么解锁前面写了。

root@taiwan:~/eos# cleos set contract eosio contracts/eosio.bios -p eosio
Reading WASM from /root/eos/contracts/eosio.bios/eosio.bios.wasm...Publishing contract...
executed transaction: ee87d30fbd1d49f3048aa975cfedae19fa1b60ab9315a096b126bc74fce827e5  7480 bytes  1831 us
#         eosio <= eosio::setcode               {"account":"eosio","vmtype":0,"vmversion":0,"code":"0061736d010000000191011860000060017f017f60017f00...
#         eosio <= eosio::setabi                {"account":"eosio","abi":"0e656f73696f3a3a6162692f312e310018086162695f686173680002056f776e6572046e61...
warn  2019-11-07T11:59:41.334 cleos     main.cpp:495                  print_result      
warning: transaction executed locally, but may not be confirmed by the network yet
  1. 创建一堆账号:
- eosio.bpay:超级节点获取出块奖励的临时代管账户,增发EOS的1%的25%会先转到这个账户

- eosio.msig:用来部署eosio.msig合约

- eosio.names:用来管理域名竞拍

- eosio.ram:用来管理ram买卖

- eosio.ramfee:用来管理ram买卖产生的手续费,每笔买卖扣1%的手续费

- eosio.saving:增发EOS临时存放账户,增发总量 5%,其中80%放在此账户,另外 20%再分成25%和75%,分别给eosio.bpay和eosio.vpay

- eosio.stake:用来管理抵押换取cpu、net资源的EOS

- eosio.token:用来部署eosio.token合约

- eosio.vpay:节点们按照获得投票多少比例获取奖励的临时代管账户,增发EOS的1%的75%会先转到这个账户

- eosio.rex:持有EOS的用户(出租者)通过系统合约发送“要出租eos的账户、出租数量”并授权

如何生成密钥对和注册账号可以看part2中的3、4、6三步。

  1. 部署eosio.token合约,部署账户为eosio.token。
root@taiwan:~/eos# cleos  set  contract  eosio.token  contracts/eosio.token  -p  eosio.token
Reading WASM from /root/eos/contracts/eosio.token/eosio.token.wasm...
Publishing contract...
executed transaction: f788b2b5609c0cb07810322c83e0c9a63b1f76a990acf5bebdfc61a8fa07f09c  7952 bytes  1702 us
#         eosio <= eosio::setcode               {"account":"eosio.token","vmtype":0,"vmversion":0,"code":"0061736d0100000001a0011b60000060017e006002...
#         eosio <= eosio::setabi                {"account":"eosio.token","abi":"0e656f73696f3a3a6162692f312e310008076163636f756e7400010762616c616e63...
warn  2019-11-07T12:07:39.317 cleos     main.cpp:495                  print_result      
warning: transaction executed locally, but may not be confirmed by the network yet
  1. 部署eosio.msig合约,部署账户为eosio.msig。
root@taiwan:~/eos# cleos  set  contract  eosio.msig  contracts/eosio.msig  -p  eosio.msig
Reading WASM from /root/eos/contracts/eosio.msig/eosio.msig.wasm...
Publishing contract...
executed transaction: faaa7e5bbc26c2d38c32099b2a3fa9781714ea23aec0612b4ccf0d3cd4870da7  10968 bytes  2495 us
#         eosio <= eosio::setcode               {"account":"eosio.msig","vmtype":0,"vmversion":0,"code":"0061736d0100000001ca011f60000060067f7f7f7f7...
#         eosio <= eosio::setabi                {"account":"eosio.msig","abi":"0e656f73696f3a3a6162692f312e31001006616374696f6e0004076163636f756e740...
warn  2019-11-07T12:09:32.708 cleos     main.cpp:495                  print_result      
warning: transaction executed locally, but may not be confirmed by the network yet
  1. 创建EOS代币,调用eosio.token账户下的eosio.token智能合约的create函数。
    cleos push action命令,用来触发eosio.token合约的create函数,代币发行账户是eosio,发行量10亿,代币的符号是EOS。
root@taiwan:~/eos# cleos  push  action  eosio.token  create  '[ "eosio", "1000000000.0000 EOS"]' -p eosio.token
executed transaction: aece2dcb68ef69d8ca1a7697fb9004c5a18fe55f281c828dfc0c9bfcfb5f26bd  120 bytes  433 us
#   eosio.token <= eosio.token::create          {"issuer":"eosio","maximum_supply":"1000000000.0000 EOS"}
warn  2019-11-07T12:10:43.496 cleos     main.cpp:495                  print_result      
warning: transaction executed locally, but may not be confirmed by the network yet
  1. 增发EOS资产并打入eosio账户,调用eosio.token账户下的eosio.token智能合约的issue函数。
root@taiwan:~/eos# cleos --url http://127.0.0.1:8888 push  action  eosio.token  issue  '[ "eosio", "1000000000.0000 EOS", "test message"]' -p eosio
executed transaction: 231954be1b90a305091dca2da998a01ab7449f02f1d94f6d85a822c3e1220550  136 bytes  602 us
#   eosio.token <= eosio.token::issue           {"to":"eosio","quantity":"1000000000.0000 EOS","memo":"test message"}
warn  2019-11-07T12:26:13.146 cleos     main.cpp:495                  print_result      
warning: transaction executed locally, but may not be confirmed by the network yet

--url http://127.0.0.1:8888是指定节点API,因为客户端可能找不到默认节点。

创建和发行以后可以使用cleos get currency stats eosio.token EOS查看EOS资产的总量、流通量等信息。

转个帐试试,注意资产精度也就是小数点后的0必须带够。

root@taiwan:~# cleos push action eosio.token transfer '[ "eosio", "test", "50000.0000 EOS", "hello eos" ]' -p eosio
executed transaction: 81d3feb91df3c50179c4f111fa8fd580c242f2cad3565eeb8993f3311b9ee3b6  136 bytes  415 us
#   eosio.token <= eosio.token::transfer        {"from":"eosio","to":"test","quantity":"50000.0000 EOS","memo":"hello eos"}
#         eosio <= eosio.token::transfer        {"from":"eosio","to":"test","quantity":"50000.0000 EOS","memo":"hello eos"}
#         test <= eosio.token::transfer        {"from":"eosio","to":"test","quantity":"50000.0000 EOS","memo":"hello eos"}
warn  2019-11-07T12:38:22.170 cleos     main.cpp:495                  print_result      
warning: transaction executed locally, but may not be confirmed by the network yet

  1. 部署eosio.system合约,部署账户为eosio。
root@taiwan:~/eos# cleos  set  contract  eosio  contracts/eosio.system  -p  eosio -x 1000
Reading WASM from /root/eos/contracts/eosio.system/eosio.system.wasm...
Publishing contract...
executed transaction: 9a3899daa0c922bc4be38f463c12ee627868a4ac90fccb4be7199c2ff82ce1d8  78264 bytes  13057 us
#         eosio <= eosio::setcode               {"account":"eosio","vmtype":0,"vmversion":0,"code":"0061736d0100000001b7033e60000060047f7f7f7f006004...
#         eosio <= eosio::setabi                {"account":"eosio","abi":"0e656f73696f3a3a6162692f312e310055086162695f686173680002056f776e6572046e61...
warn  2019-11-07T12:53:57.304 cleos     main.cpp:495                  print_result      
warning: transaction executed locally, but may not be confirmed by the network yet
  1. 使用cleos system newaccount命令创建普通账户
    这里创建账户使用cleos system newaccount命令,这是eos上创建普通账户所用的命令,底层实际上调用的是eosio.system合约的newaccount函数。
    而cleos create account命令,其实是为了eosio账户创建系统账户提供的命令,需要特殊权限才能执行。
    新创建的账户,需要抵押一定的EOS去换取cpu、net资源,需要花费一定EOS去买ram资源,用于交易的发送。用于抵押cpu和net的EOS是可以赎回的,赎回需要3天时间。
    资源的分配是按比例的。比如,抵押全网1%的eos,就可以换取全网1%的cpu或者net资源。
    cpu和net资源是可再生的,使用后一天就可恢复,ram是不可再生资源,用完得再买。

参数格式:cleos system newaccount [OPTIONS] creator name OwnerKey [ActiveKey] --stake-net TEXT --stake-cpu TEXT --buy-ram TEXT
eosio账户创建了一个账户voter1,为这个新账户抵押了20000EOS、20000EOS去换取cpu和net资源,付费20000EOS为这个账户买了ram资源:

root@taiwan:~/eos# cleos system newaccount eosio voter1 EOS5zKp4TQT8sLzjjPsZovyfncvMdDkYFyZFFRSRXEk2CZ1GSyzkn EOS5NC7uUuDcm3nQcSXksMo3GaZ4VUQWt9PLeMizvHefeqgn12PzU --stake-net "20000 EOS" --stake-cpu "20000 EOS" --buy-ram "20000 EOS"
executed transaction: 58d3e246d3367a55037b99e353612da779acdbbe5c8b49c6e55b505218837714  344 bytes  964 us
#         eosio <= eosio::newaccount            {"creator":"eosio","name":"voter1","owner":{"threshold":1,"keys":[{"key":"EOS5zKp4TQT8sLzjjPsZovyfnc...
#         eosio <= eosio::buyram                {"payer":"eosio","receiver":"voter1","quant":"20000.0000 EOS"}
#   eosio.token <= eosio.token::transfer        {"from":"eosio","to":"eosio.ram","quantity":"19900.0000 EOS","memo":"buy ram"}
#         eosio <= eosio.token::transfer        {"from":"eosio","to":"eosio.ram","quantity":"19900.0000 EOS","memo":"buy ram"}
#     eosio.ram <= eosio.token::transfer        {"from":"eosio","to":"eosio.ram","quantity":"19900.0000 EOS","memo":"buy ram"}
#   eosio.token <= eosio.token::transfer        {"from":"eosio","to":"eosio.ramfee","quantity":"100.0000 EOS","memo":"ram fee"}
#         eosio <= eosio.token::transfer        {"from":"eosio","to":"eosio.ramfee","quantity":"100.0000 EOS","memo":"ram fee"}
#  eosio.ramfee <= eosio.token::transfer        {"from":"eosio","to":"eosio.ramfee","quantity":"100.0000 EOS","memo":"ram fee"}
#         eosio <= eosio::delegatebw            {"from":"eosio","receiver":"voter1","stake_net_quantity":"20000.0000 EOS","stake_cpu_quantity":"20...
#   eosio.token <= eosio.token::transfer        {"from":"eosio","to":"eosio.stake","quantity":"40000.0000 EOS","memo":"stake bandwidth"}
#         eosio <= eosio.token::transfer        {"from":"eosio","to":"eosio.stake","quantity":"40000.0000 EOS","memo":"stake bandwidth"}
#   eosio.stake <= eosio.token::transfer        {"from":"eosio","to":"eosio.stake","quantity":"40000.0000 EOS","memo":"stake bandwidth"}
warn  2019-11-07T18:04:19.493 cleos     main.cpp:495                  print_result      
warning: transaction executed locally, but may not be confirmed by the network yet

在这一步可能会报错:

root@taiwan:~/eos# cleos system newaccount eosio voter1 EOS5zKp4TQT8sLzjjPsZovyfncvMdDkYFyZFFRSRXEk2CZ1GSyzkn EOS5NC7uUuDcm3nQcSXksMo3GaZ4VUQWt9PLeMizvHefeqgn12PzU --stake-net "20000 EOS" --stake-cpu "20000 EOS" --buy-ram "20000 EOS"
Error 3050003: eosio_assert_message assertion failure
Error Details:
assertion failure with message: system contract must first be initialized

这是因为在部署完eosio.system后,需要执行init才能使用某些功能:https://github.com/EOSIO/eos/issues/7061

root@taiwan:~/eos# cleos push action eosio init '[0,"4,EOS"]' -p eosio@active
executed transaction: 3acead63272dd429a0838b49b07c0cdd48e6c9c829b16ab06ff026a7efbb0ef6  104 bytes  426 us
#         eosio <= eosio::init                  {"version":0,"core":"4,EOS"}
#   eosio.token <= eosio.token::open            {"owner":"eosio.rex","symbol":"4,EOS","ram_payer":"eosio"}
warn  2019-11-07T18:04:06.370 cleos     main.cpp:495                  print_result      
warning: transaction executed locally, but may not be confirmed by the network yet

在上面这步,要求已创建 rex_account eosio.rex账户再执行部署eosio.system合约,否则会报错Error 3050003:...... owner account does not exist,实际上,步骤二中的每个账户都需要创建。 https://github.com/EOSIO/eos/issues/7710

  1. 投票选举超级节点

上一步,我们创建两个账户voter1和bp1。eos的主链或者私链,初始的时候都是被系统账户eosio控制的。但是,如果想要激活eos的所有功能,则必须投票选举超级节点,且全网投票必须超过发行总量的15%,即1.5个亿。主链上是选举21个超级节点,它们轮流出块。私链上,我们只需要选举一个超级节点,让它出块即可。下面,我们将为大家演示超级节点的选举过程。

eosio将1.5亿EOS转账给voter1

root@taiwan:~/eos# cleos transfer eosio voter1 "150000000.0000 BASHE" -p eosio
executed transaction: 1f7b4fd418658e3c1c00d74e1db7c2470823944c01d64501153d2704d51c5230  128 bytes  542 us
#   eosio.token <= eosio.token::transfer        {"from":"eosio","to":"voter1","quantity":"150000000.0000 BASHE","memo":""}
#         eosio <= eosio.token::transfer        {"from":"eosio","to":"voter1","quantity":"150000000.0000 BASHE","memo":""}
#        voter1 <= eosio.token::transfer        {"from":"eosio","to":"voter1","quantity":"150000000.0000 BASHE","memo":""}
warn  2019-11-15T07:53:36.248 cleos     main.cpp:495                  print_result 
warning: transaction executed locally, but may not be confirmed by the network yet

voter1将EOS抵押为cpu、net资源,因为只有抵押为资源的EOS才能用于投票。

cleos  system  delegatebw  voter1  voter1  "150000000.0000 BASHE"  "0 BASHE"

我们抵押了1.5亿 EOS去换cpu资源,0 EOS去换net资源。cleos  system  delegatebw命令详情如下,from是出抵押的EOS的账户,to是接收抵押资源的账户,stake_net_quantity和stake_cpu_quantity是抵押EOS的金额:

root@taiwan:~/eos# cleos  system  delegatebw  voter1  voter1  "150000000.0000 BASHE"  "0 BASHE"
executed transaction: 2f3cb4fc4bc753fd2f396eda467c418fc977a77a5df3574fd38a3f1592c32e63  144 bytes  838 us
#         eosio <= eosio::delegatebw            {"from":"voter1","receiver":"voter1","stake_net_quantity":"150000000.0000 BASHE","stake_cpu_quantity...
#   eosio.token <= eosio.token::transfer        {"from":"voter1","to":"eosio.stake","quantity":"150000000.0000 BASHE","memo":"stake bandwidth"}
#        voter1 <= eosio.token::transfer        {"from":"voter1","to":"eosio.stake","quantity":"150000000.0000 BASHE","memo":"stake bandwidth"}
#   eosio.stake <= eosio.token::transfer        {"from":"voter1","to":"eosio.stake","quantity":"150000000.0000 BASHE","memo":"stake bandwidth"}
warn  2019-11-15T08:01:04.518 cleos     main.cpp:495                  print_result 
warning: transaction executed locally, but may not be confirmed by the network yet

将bp1注册为超级节点,只有注册的账户,其他账户才能给它投票 cleos system regproducer bp1 <bp1's public key>

root@taiwan:~/eos# cleos  system  regproducer  bp1 EOS5zKp4TQT8sLzjjPsZovyfncvMdDkYFyZFFRSRXEk2CZ1GSyzkn
executed transaction: 726449ffa8f77983202e86b4e625b95658426d4868966d0a5c277d995305eba5  144 bytes  27423 us
#         eosio <= eosio::regproducer           {"producer":"bp1","producer_key":"EOS5zKp4TQT8sLzjjPsZovyfncvMdDkYFyZFFRSRXEk2CZ1GSyzkn","url":"","l...
warn  2019-11-15T08:14:16.188 cleos     main.cpp:495                  print_result 
warning: transaction executed locally, but may not be confirmed by the network yet


截至目前用过的命令和顺序,换行表示需要前后命令不可批量连续执行:

screen -r node1

curl -X POST http://127.0.0.1:8888/v1/producer/schedule_protocol_feature_activations -d '{"protocol_features_to_activate": ["0ec7e080177b2c02b278d5088611686b49d739925a92d9bfcacd7fc6b74053bd"]}' | jq

cleos set contract eosio contracts/eosio.bios -p eosio

cleos create account eosio  eosio.names  EOS5zKp4TQT8sLzjjPsZovyfncvMdDkYFyZFFRSRXEk2CZ1GSyzkn EOS5NC7uUuDcm3nQcSXksMo3GaZ4VUQWt9PLeMizvHefeqgn12PzU
cleos create account eosio  eosio.ram  EOS5zKp4TQT8sLzjjPsZovyfncvMdDkYFyZFFRSRXEk2CZ1GSyzkn EOS5NC7uUuDcm3nQcSXksMo3GaZ4VUQWt9PLeMizvHefeqgn12PzU
cleos create account eosio  eosio.ramfee  EOS5zKp4TQT8sLzjjPsZovyfncvMdDkYFyZFFRSRXEk2CZ1GSyzkn EOS5NC7uUuDcm3nQcSXksMo3GaZ4VUQWt9PLeMizvHefeqgn12PzU
cleos create account eosio  eosio.saving  EOS5zKp4TQT8sLzjjPsZovyfncvMdDkYFyZFFRSRXEk2CZ1GSyzkn EOS5NC7uUuDcm3nQcSXksMo3GaZ4VUQWt9PLeMizvHefeqgn12PzU
cleos create account eosio  eosio.stake  EOS5zKp4TQT8sLzjjPsZovyfncvMdDkYFyZFFRSRXEk2CZ1GSyzkn EOS5NC7uUuDcm3nQcSXksMo3GaZ4VUQWt9PLeMizvHefeqgn12PzU
cleos create account eosio  eosio.rex  EOS5zKp4TQT8sLzjjPsZovyfncvMdDkYFyZFFRSRXEk2CZ1GSyzkn EOS5NC7uUuDcm3nQcSXksMo3GaZ4VUQWt9PLeMizvHefeqgn12PzU
cleos create account eosio  eosio.token  EOS5zKp4TQT8sLzjjPsZovyfncvMdDkYFyZFFRSRXEk2CZ1GSyzkn EOS5NC7uUuDcm3nQcSXksMo3GaZ4VUQWt9PLeMizvHefeqgn12PzU
cleos create account eosio  eosio.vpay  EOS5zKp4TQT8sLzjjPsZovyfncvMdDkYFyZFFRSRXEk2CZ1GSyzkn EOS5NC7uUuDcm3nQcSXksMo3GaZ4VUQWt9PLeMizvHefeqgn12PzU
cleos create account eosio  eosio.bpay  EOS5zKp4TQT8sLzjjPsZovyfncvMdDkYFyZFFRSRXEk2CZ1GSyzkn EOS5NC7uUuDcm3nQcSXksMo3GaZ4VUQWt9PLeMizvHefeqgn12PzU
cleos create account eosio  eosio.msig  EOS5zKp4TQT8sLzjjPsZovyfncvMdDkYFyZFFRSRXEk2CZ1GSyzkn EOS5NC7uUuDcm3nQcSXksMo3GaZ4VUQWt9PLeMizvHefeqgn12PzU
cleos create account eosio  bashe  EOS5zKp4TQT8sLzjjPsZovyfncvMdDkYFyZFFRSRXEk2CZ1GSyzkn EOS5NC7uUuDcm3nQcSXksMo3GaZ4VUQWt9PLeMizvHefeqgn12PzU
cleos  set  contract  eosio.token  contracts/eosio.token  -p  eosio.token
cleos  set  contract  eosio.msig  contracts/eosio.msig  -p  eosio.msig
cleos  push  action  eosio.token  create  '[ "eosio", "1000000000.0000 BASHE"]' -p eosio.token
cleos --url http://127.0.0.1:8888 push  action  eosio.token  issue  '[ "eosio", "1000000000.0000 BASHE", "test message"]' -p eosio

cleos push action eosio init '[0,"4,BASHE"]' -p eosio@active

cleos  set  contract  eosio  contracts/eosio.system  -p  eosio -x 1000

cleos system newaccount eosio voter1 EOS5zKp4TQT8sLzjjPsZovyfncvMdDkYFyZFFRSRXEk2CZ1GSyzkn EOS5NC7uUuDcm3nQcSXksMo3GaZ4VUQWt9PLeMizvHefeqgn12PzU --stake-net "20000 BASHE" --stake-cpu "20000 BASHE" --buy-ram "20000 BASHE"

cleos system newaccount eosio bp1 EOS5zKp4TQT8sLzjjPsZovyfncvMdDkYFyZFFRSRXEk2CZ1GSyzkn EOS5NC7uUuDcm3nQcSXksMo3GaZ4VUQWt9PLeMizvHefeqgn12PzU --stake-net "20000 BASHE" --stake-cpu "20000 BASHE" --buy-ram "20000 BASHE"

cleos wallet unlock -n bashe --password PW5KN54uTaavZuK5muCupy8Drd6UaEEw14geyupyt7ksXu2EtBqQb    

cleos transfer eosio voter1 "150000000.0000 BASHE" -p eosio

下载安装EOSIO.CDT ,这是EOS的智能合约开发工具。

wget https://github.com/eosio/eosio.cdt/releases/download/v1.6.3/eosio.cdt_1.6.3-1-ubuntu-18.04_amd64.deb
sudo apt install ./eosio.cdt_1.6.3-1-ubuntu-18.04_amd64.deb

可能会遇到这个报错,是因为_apt没有权限的原因。

N: Download is performed unsandboxed as root as file '/root/eosio.cdt_1.6.3-1-ubuntu-18.04_amd64.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)

赋予_apt /root目录下的权限

sudo chown -R  _apt /root

卸载并重新安装eosio.cdt

sudo apt remove eosio.cdt
sudo apt install ./eosio.cdt_1.6.3-1-ubuntu-18.04_amd64.deb

参考文章:
https://developers.eos.io/eosio-cleos/docs/connecting-to-non-default-hostport
https://www.jianshu.com/p/90dea623ffdf
https://www.jianshu.com/p/99bdf3f908f6
https://www.jianshu.com/p/c6b51fb4ad8a

点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注

Captcha Code