爲了研究Neo的代碼,須要看一下Neo到底怎麼運行的,在網絡上跑一個智能合約,而且調試該網絡。因此先搭建一個私鏈玩玩。html
NEO 私有鏈的部署至少須要 4 臺服務器才能取得共識,每臺服務器對應一個共識節點。在阿里雲上能夠買按量付費的虛擬機(機器都是window server)。
記錄下四臺機器的內網IP地址,後面要用。node
172.xxx.xxx.142
若是你想讓外部程序訪問該節點的 API 須要開放防火牆端口:10331-10334, 20331-20334
阿里雲的vpc若是在一個安全組內就不須要設置。也能夠經過安全組開放全部入口。git
阿里雲安全組github
運行 NEO 節點須要安裝 .NET Core Runtime,須要安裝 1.0.1 或以上版本數據庫
在 Windows 系統下安裝 .NET Core 很是方便,直接下載運行便可。json
NOTE安全
Windows可能還須要安裝Microsoft Visual C++ 2015 Redistributable Update 3(https://www.microsoft.com/en-us/download/details.aspx?id=53840) ,不然後面沒法啓動Neo-CLI。服務器
在四臺機器上分別建立錢包數據庫,數據庫文件會默認生成在neo-cli的目錄下面網絡
create wallet wallet.json
neo1區塊鏈
neo> create wallet wallet.db3 Wallet files in db3 format are not supported, please use a .json file extension. neo> create wallet wallet.json password: ******** password: ******** address: AS43TUy7VtuGpNJh2YC2NM3asTv3s6piyk pubkey: 02d57c9bbc42b45943867dff0180cb9df266b46db7d027a283eabc7c4b8819c86c
記錄下另外幾臺機器的錢包公鑰
neo2
address: AY35ZjJayg9JfmCeHg1nySN4LSMntFEq2h pubkey: 035022ce81faca930ebe6b9f8e830526150e47692f19f58affe1311e42cd0d43bb
neo3
address: AQZNtdGVXbfot5fSaR4ijBqrEwbnFQspmH pubkey: 029f21d56f9422e55f0ef7cf75c092854e01c99aeee73f0effeaa489a96fc7d2b1
neo4
address: AXctyT8ctWTXtWaUFM9o5FJas8BWdBbiqe pubkey: 02dc0e750e21c386537618079d89836eea39fad396206e2e56cfba16bdc014dc5d
{ "ProtocolConfiguration": { "Magic": 1, "AddressVersion": 23, "StandbyValidators": [ "02d57c9bbc42b45943867dff0180cb9df266b46db7d027a283eabc7c4b8819c86c", "035022ce81faca930ebe6b9f8e830526150e47692f19f58affe1311e42cd0d43bb", "029f21d56f9422e55f0ef7cf75c092854e01c99aeee73f0effeaa489a96fc7d2b1", "02dc0e750e21c386537618079d89836eea39fad396206e2e56cfba16bdc014dc5d" ], "SeedList": [ "172.24.198.142:10333", "172.24.198.141:10333", "172.24.198.140:10333", "172.24.198.139:10333" ], "SystemFee": { "EnrollmentTransaction": 0, "IssueTransaction": 0, "PublishTransaction": 0, "RegisterTransaction": 0 } } }
open wallet wallet.json start consensus
若是前面打開過cli,請刪除chain目錄下的文件,這樣區塊鏈高度會從1開始。
neo> open wallet wallet.json password: ******** neo> start consensus [18:04:31] OnStart [18:04:31] initialize: height=1 view=0 index=0 role=Backup [18:04:47] OnChangeViewReceived: height=1 view=0 index=2 nv=2 [18:05:01] timeout: height=1 view=0 state=Backup [18:05:01] request change view: height=1 view=0 nv=1 state=Backup, ViewChanging [18:05:58] OnPrepareRequestReceived: height=1 view=0 index=1 tx=1 [18:05:58] send perpare response [18:06:01] OnPrepareResponseReceived: height=1 view=0 index=2 [18:06:01] relay block: 0x8515184285fa2e454b0eca441580b5cce01cc0e5cb5dd6d7ff53ef13ec7f665e [18:06:01] persist block: 0x8515184285fa2e454b0eca441580b5cce01cc0e5cb5dd6d7ff53ef13ec7f665e [18:06:01] initialize: height=2 view=0 index=0 role=Backup [18:06:16] OnPrepareRequestReceived: height=2 view=0 index=2 tx=1 [18:06:16] send perpare response [18:06:19] OnPrepareResponseReceived: height=2 view=0 index=1 [18:06:19] relay block: 0x35b163f4f524a1ebcc1ef3053e878f9bb37b1f4a8531a060ef18cfd6efefdf45 [18:06:19] persist block: 0x35b163f4f524a1ebcc1ef3053e878f9bb37b1f4a8531a060ef18cfd6efefdf45 [18:06:19] initialize: height=3 view=0 index=0 role=Backup [18:06:49] timeout: height=3 view=0 state=Backup [18:06:49] request change view: height=3 view=0 nv=1 state=Backup, ViewChanging [18:06:49] OnChangeViewReceived: height=3 view=0 index=1 nv=1 [18:06:53] OnChangeViewReceived: height=3 view=0 index=2 nv=1 [18:06:53] initialize: height=3 view=1 index=0 role=Backup [18:06:55] OnPrepareRequestReceived: height=3 view=1 index=2 tx=1 [18:06:55] send perpare response [18:06:55] OnPrepareResponseReceived: height=3 view=1 index=1 [18:06:55] relay block: 0x1766a0602903f513f76561c93fddf312f70d30801310abfecacc89feace5c412 [18:06:55] persist block: 0x1766a0602903f513f76561c93fddf312f70d30801310abfecacc89feace5c412 [18:06:55] initialize: height=4 view=0 index=0 role=Primary [18:07:10] timeout: height=4 view=0 state=Primary [18:07:10] send perpare request: height=4 view=0 [18:07:13] OnPrepareResponseReceived: height=4 view=0 index=3 [18:07:13] OnPrepareResponseReceived: height=4 view=0 index=2 [18:07:13] relay block: 0x5233d9086db97e59f86d73e8735093c1b3fe4569759697ff8a04e0eb8f389091 [18:07:13] persist block: 0x5233d9086db97e59f86d73e8735093c1b3fe4569759697ff8a04e0eb8f389091 [18:07:13] initialize: height=5 view=0 index=0 role=Backup
原來文章中有提取neo和gas的方法,可是我如今還不知道爲何要提取Neo,有什麼意義,先跟着文檔跑着看看。我用的window server會遇到crash,詳情請看https://github.com/neo-project/neo-gui/issues/171
但願Neo社區的大牛能解決一下這個問題。
一天後,社區給出的解決方案https://github.com/neo-project/neo-gui/issues/171,須要下載兩個包
雖然配置成功了,可是還不知道能幹嘛,須要進一步研究。提取Neo也遇到崩潰的狀況,發現這個問題,也算作貢獻了。
基於NEO的私鏈(Private Blockchain)
用 NEO 節點搭建私有鏈 做者:沈寅 連接:https://www.jianshu.com/p/df476db9aad5