一环境准备
1Go-Ethereum
Go-Ethereum是由以太坊基金会提供的官方客户端软件。它是用Go编程语言编写的,简称Geth。可以按照以下wiki说明安装go-ethereum,地址为:https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum。
这里简单介绍一下在mac上通过源码安装的步骤:
1)下载geth源码:
git clone https://github.com/ethereum/go-ethereum
2)安装go环境
brew install go
3)compile、build、install geth
cd go-ethereum
make geth
4)xcode支持
If you see some errors related to header files of Mac OS system library, install XCode Command Line Tools, and try again.
xcode-select --install
5)测试安装是否成功
执行命令:geth version,如果出现以下信息说明安装成功
> geth version
Geth
Version: 1.8.14-stable
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.10.3
Operating System: darwin
GOPATH=/Users/wuzhengfei/Documents/workspace/go/workspace
GOROOT=/usr/local/go
二搭建私有链
在go-ethereum中详细介绍了搭建私有链的过程,有兴趣的话,可以详细看一下。
1常见创世区块
1)常见创世区块
首先需要为区块链创建一个创世区块,所有的区块都会挂在这个创世区块的后面。创建一个json文件(这里命名为genesis.json),其内容如下:
{
"config": {
"chainId": 0,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"alloc": {},
"coinbase": "0x0000000000000000000000000000000000000000",
"difficulty": "0x20000",
"extraData": "",
"gasLimit": "0x2fefd8",
"nonce": "0x0000000000055555",
"mixhash": "0x00000000000000000000