本文主要介绍了本地的eos程序如何连接主网。

1. 我们在EOS主网上么

这时我们在命令行中输入:

cleos get info

会显示如下界面:notmain_chainid

注意到里面有一个chain_id字段,它的值是cf057...c4f,这是它所在的网络标识符,主网的chain_id的值是:aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906,很明显我们并没有在主网中,所以我们的姿势是不对的,到底问题出在哪儿呢?

2. 连接主网 - 指定genesis-json

接着上面的问题,答案就是在我们运行nodeos时,是需要指定genesis-json的,送给大家一份genesis.json

{
  "initial_timestamp": "2018-06-08T08:08:08.888",
  "initial_key": "EOS7EarnUhcyYqmdnPon8rm7mBCTnBoot6o7fE2WzjvEX2TdggbL3",
  "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
  }
}

在主目录下新创建一个genesis.json文件,并把上面的内容复制粘贴进去即可。

3. 连接主网 - 添加插件列表

但这并没有结束,我们还需要指定运行时的插件:

~/Library/Application\ Support/eosio/nodeos/config/config.ini中添加插件列表:

plugin = eosio::chain_plugin
plugin = eosio::chain_api_plugin
plugin = eosio::net_plugin
plugin = eosio::net_api_plugin
plugin = eosio::history_plugin
plugin = eosio::history_api_plugin
plugin = eosio::http_plugin
plugin = eosio::http_client_plugin
plugin = eosio::wallet_api_plugin

之后我们再运行nodeos --genesis-json ~/genesis.json,这时我们又遇到了一个错误:

fresh_err

解决的办法简单粗暴,直接删除原来的数据:

rm -rf  ~/Library/Application\ Support/eosio/nodeos/data

或者在启动nodeos时追加--delete-all-blocks参数即可。

nodeos --genesis-json ~/genesis.json --delete-all-blocks

4. 连接主网 - 添加种子节点

这时我们看上去似乎没啥问题了,cleos get info之后出来的也是主网id,一切看上去岁月静好。

但是等等,为什么我电脑只有一个块,执行cleos get block 2就会报错,说好的主网,难道是单机版?

节点要同步数据,就必须知道从哪个节点同步数据。这要靠显示声明的种子节点来解决,这些种子节点通常是EOS的创建者和运营者。同样,我们在之前的config.ini文件中继续追加种子节点信息:

p2p-peer-address = p2p.prod.eosgravity.com:80
p2p-peer-address = eu-west-nl.eosamsterdam.net:9876
p2p-peer-address = p2p.mainnet.eosgermany.online:9876
p2p-peer-address = 54.38.250.15:19878
p2p-peer-address = p2p.genereos.io:9876
p2p-peer-address = mainnet.eospay.host:19876
p2p-peer-address = 130.211.59.178:9876
p2p-peer-address = 54.153.59.31:9999
p2p-peer-address = 94.130.250.22:9806  
p2p-peer-address = peer.main.alohaeos.com:9876
p2p-peer-address = peer.eosn.io:9876
p2p-peer-address = prod.mainnet.eos.cybex.io:9888
p2p-peer-address = p2p-1.eosnetwork.io:9876
p2p-peer-address = p.jeda.one:3322
p2p-peer-address = eosbattles.com:9877
p2p-peer-address = 34.226.76.22:9876
p2p-peer-address = mainnet.eosoasis.io:9876
p2p-peer-address = node.eosflare.io:1883
p2p-peer-address = p2p.eosio.cr:1976
p2p-peer-address = p2p.eosio.cr:5418
p2p-peer-address = eno.eosvan.io:19866

之后再执行nodeos(这次就不要加后面的参数啦),这时发现开始开始找邻近节点同步信息了。

再执行cleos get info,出现如下界面:

eos_getinfo_right

chain_id确实是主网ID,执行cleos get block n(n为区块号)也不报错啦,同步成功!

至此,我们终于和主网大部队汇合啦!

总结

该篇我们学习了:

  • 如何连接到EOS主网

    • 指定genesis-json来修改chain_id
    • 修改config.ini文件

      • 添加plugin相关语句
      • 添加p2p-peer-address列表
    • 启动时清空已有的区块链数据信息 --delete-all-blocks

结束语

这章我们学习了如何判断自己在不在主网上,并且如何连接EOS主网。下一章我们来说说cleos、账户的概念,以及操作钱包做点实事儿。


王铁塔
33 声望29 粉丝