区块链学习(二)Mac系统下EOS区块链开发环境

一、从GitHub上克隆主网代码仓库:(注意EOS-Mainnet/eos 与 EOSIO/eos 的版本是一致的。若以前在本地已经安装编译过EOSIO/eos的1.0.2版本及以上,则可以直接跳到步骤三),最新版本是1.1.6

git clone https://github.com/EOS-Mainnet/eos 
cd eos
git submodule update --init --recursive 
git tag
git checkout mainnet-1.1.6

二、编译eos代码

./eosio_build.sh  

三、替换config.ini 和 genesis.json 文件

(1)运行nodeos节点后会生成默认的config.ini/genesis.json文件,现在对其进行替换

(2)在不同系统中找到其文件地址:

  • linux-ubuntu: ~/.local/share/eosio/nodeos/config/
  • mac-osx: ~/Library/Application\ Support/eosio/nodeos/config/

(3)新的config.ini文件设置如下:

# fullnode sample config

blocks-dir = "blocks"

chain-state-db-size-mb = 1024

reversible-blocks-db-size-mb = 340

contracts-console = false

https-client-validate-peers = 1

http-server-address = 0.0.0.0:8888

access-control-allow-credentials = false

p2p-listen-endpoint = 0.0.0.0:9876

p2p-server-address = 0.0.0.0:9876


# List of peers

p2p-peer-address = p2p.one.eosdublin.io:9876

p2p-peer-address = eu-west-nl.eosamsterdam.net:9876

p2p-peer-address = p2p.mainnet.eosgermany.online:9876

p2p-peer-address = 35.197.190.234:19878

p2p-peer-address = p2p.genereos.io:9876

p2p-peer-address = fullnode.eoslaomao.com:443

p2p-peer-address = new.eoshenzhen.io:10034

p2p-peer-address = node1.eosphere.io:9876

p2p-peer-address = p2p.meet.one:9876

p2p-peer-address = bp.eosbeijing.one:8080

p2p-peer-address = peer1.mainnet.helloeos.com.cn:80

p2p-peer-address = p2p-public.hkeos.com:19875

p2p-peer-address = pub1.eostheworld.io:9876

p2p-peer-address = eu1.eosdac.io:49876

p2p-peer-address = peer.eosio.sg:9876


p2p-max-nodes-per-host = 10


agent-name = "eosmainnet"

# allowed-connection can be set to "specified" to use whitelisting with the "peer-key" option

allowed-connection = any


# peer-private-key is needed if you are whitelisting specific peers with the "peer-key" option

peer-private-key = ["EOS6qTvpRYx35aLonqUkWAMwAf3mFVugYfQCbjV67zw2aoe7Vx7qd", "5JroNC1B4pz9gJzNZeU7tkU6YMtoeWRCr4CJJwKsVXnJhRbKXSC"]


max-clients = 250

connection-cleanup-period = 30

network-version-match = 1

sync-fetch-span = 100

max-implicit-request = 1500

enable-stale-production = false

pause-on-startup = false

max-transaction-time = 10000

max-irreversible-block-age = -1

txn-reference-block-lag = 0


# Plugins used for full nodes

plugin = eosio::chain_api_plugin

plugin = eosio::history_api_plugin

plugin = eosio::chain_plugin

plugin = eosio::history_plugin

plugin = eosio::net_plugin

plugin = eosio::net_api_plugin

其中p2p-peer-address的配置来源于:

https://docs.google.com/spreadsheets/d/1K_un5Vak3eDh_b4Wdh43sOersuhs0A76HMCfeQplDOY/edit#gid=0

(4)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
  }
}

此文件称为创世json文件,来自以下链接:

https://github.com/EOS-Mainnet/eos/blob/launch-rc-1.0.2/mainnet-genesis.json

四、将以上的创世json文件,复制拷贝到~/eos/build/program/nodeos目录下,并启动nodeos节点:

./nodeos --genesis-json genesis.json  

启动和连接可能不会那么顺利,我是用下面的命令的

./nodeos --data-dir . --config-dir . --genesis-json genesis.json

注意:编译完成后相关的程序都在:/Users/[your name]/eos-mainnet/eos/build/programs/nodeos

五、连接主网查看链信息:

EOS钱包推荐,imtoken,需要找一个已有eos账户的帮忙才可以噢,因为要买cpu和内存

eos一些常用的命令学习:

cleos create key #创建公钥私钥对,用于创建钱包等
cleos get info
cleos get block 191
因为现在主网数据已经很多了,到12325622个block了,所以要同步数据是很慢的,我们直接不同步数据,直连主网
cleos -u https://api.eosnewyork.io get account yiguidyiguid

 

发表评论

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