Mac搭建以太坊私有链

记录过程与问题

一、安装

以go版本的ethereum进行安装

brew tap ethereum/ethereum
brew install ethereum

# 如果希望基于ethereum的develop分支安装,执行 brew install ethereum --devel

问题:

1、由于我的MacOS系统一直没有更新,导致安装不上,提示XCode版本过低,更新XCode时又提示OS版本过低,没办法重新更新了macos monterey到最新版,然后把所有软件都重新更新了一次

2、go安装过程中出现问题,我是单独进行了go的安装才继续进行下去

安装成功后,可通过 geth --help 查看是否安装好

 

二、初始化(写入创世区块)

自定义一个创世区块的json配置文件genesis.json,与保存数据目录data

{
    "config": {
        "chainId": 15,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
    "alloc": {},
    "nonce": "0x0000000000000042",
    "difficulty": "0x020000",
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "coinbase": "0x0000000000000000000000000000000000000000",
    "timestamp": "0x00",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
    "gasLimit": "0x4c4b40"
}

 

 然后运行初始化命令:

geth --datadir "./data" init ./genesis.json

结果异常如下:

 

 原因:用比较短的negative代码写初始块,会报错。修改json如下:

{
  "config": {
    "chainId": 666,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0,
    "ethash": {}
  },
  "nonce": "0x0",
  "timestamp": "0x5ddf8f3e",
  "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x47b760",
  "difficulty": "0x00002",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "alloc": { },
  "number": "0x0",
  "gasUsed": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}

重复运行初始化命令,初始化成功

 

 此时目录结构变成如下情况:

Mac搭建以太坊私有链_第1张图片

 

 其中,keystore用来保存账户信息,geth用来保存区块信息

 

三、启动私有链节点

geth --datadir "./data" --networkid 1001 console

–networkid选项后面跟一个数字,这里是1108,表示指定这个私有链的网络id为1108。网络id在连接到其他节点的时候会用到,以太坊公网的网络id是1,为了不与公有链网络冲突,运行私有链节点的时候要指定自己的网络id

输出如下内容即表示成功:

Mac搭建以太坊私有链_第2张图片

 

 

先记录到这里,下一章写创建账户与多私有节点挖矿

 

你可能感兴趣的:(Mac搭建以太坊私有链)