劇情回顧:

對於多數人使用的系統是 Windows,所以本篇將描述如何在 Windows 上建立以太坊私有鏈。

下載 Go Ethereum Windows 版本

下載方式和 MacOS 是一樣的,可以到 Go Ethereum網站 下載,這部分可以參考第一篇文章

Fig. 1. go-ethereum for windows.
Fig. 1. go-ethereum for windows.

啟動以太坊

安裝完成後,打開命令提示字元(CMD),輸入以下指令來啟動以太坊節點。

$ geth

在資訊欄中找到 dir,這是存放鏈數據的位置。

接下來的步驟是創建一個「創世區塊」。

你可以根據需要進行細部修改,將下面的內容保存到 genesis.json 文件中,並將該文件放入鏈數據目錄中。

# genesis.json
{
  "config": {
    "chainId": 10,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0,
    "ethash": {}
  },
  "nonce": "0x0",
  "timestamp": "0x5e4a53b2",
  "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x47b760",
  "difficulty": "0x80000",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "alloc": {
    "0000000000000000000000000000000000000088": {
      "balance": "0x200000000000000000000000000000000000000000000000000000000000000"
    }
  },
  "number": "0x0",
  "gasUsed": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}

啟動私有鏈

從 CMD 切換到鏈數據目錄下,並輸入以下指令來初始化私有鏈。

$ geth init genesis.json

Fig. 2. geth init genesis json file.
Fig. 2. geth init genesis json file.

接下來使用以下命令來啟動私有鏈:

$ geth --identity "TestNode" --networkid 95518 --port "30303" --nodiscover console

Fig. 3. geth console.
Fig. 3. geth console.

未來我們將會讓兩台電腦加入到同一條鏈中,一起操作智能合約。