第一节: geth 的安装
geth是什么?
Geth是由以太坊基金会提供的官方客户端软件,用Go编程语言编写的。Geth提供了一个交互式命令控制台,通过命令控制台中包含了以太坊的各种功能(API)。全名go-ethereum,github地址go-ethereum。官方地址: geth
1 . geth的下载和安装
git clone https://github.com/ethereum/go-ethereum
cd go-ethereum
make geth
注意: gcc和go环境,以太坊的基于go来写的。
2. 启动
启动之前需要创建一个创世文件, 格式如下:
{
"config": {
"chainId": 100,
"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"
}
config项是定义链配置,会影响共识协议,虽然链配置对创世影响不大,但新区块的出块规则均依赖链配置。nonce:随机数,对应创世区块 Nonce 字段。后面的所有的链操作都会有这个。
timestamp:UTC时间戳,对应创世区块 Time字段。
extraData:额外数据,对应创世区块 Extra 字段。做区块链数据的时候用到
gasLimit:必填,燃料上限,对应创世区块 GasLimit 字段。此字段以后会经常用到,相当于手续费。
difficulty:必填,难度系数,对应创世区块 Difficulty 字段。搭建私有链时,需要根据情况选择合适的难度值,以便调整出块。
minHash:一个哈希值,对应创世区块的MixDigest字段。和 nonce 值一起证明在区块上已经进行了足够的计算。
coinbase:一个地址,对应创世区块的Coinbase字段。 把创世的文件放到一个目录,如图: 
genesis.json就是创世文件,内容就是上面的json。
初始化创世文件,执行:
./geth --datadir "./chain" init genesis.json
不出意外的话就会出现一个chain文件夹,如图:

现在就可以启动了,命令如下:
./geth --identity "TestNode1" --datadir "./chain" --rpc --rpcapi "db,eth,net,web3,personal,miner" --rpcaddr "0.0.0.0" --rpcport "8545" --networkid "100" --rpccorsdomain "*" --nodiscover --allow-insecure-unlock console 2>> eth.log
成功会进入console控制台,画面如下:

默认有一个创世账号,就可以启动挖矿了:

查看日志:

当percentage等于100是就可以看到挖矿了:

至此,geth控制台启动成功,后面的操作都是基于此的。
4817

被折叠的 条评论
为什么被折叠?



