私有链
搭建私有链,首先需要写一个创世块文件,创世块就是我自己链上的第一个区块。
{
"config":{},
"nonce":"0x0000000000000042",
"mixhash":"0x0000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x100",
"alloc": {},
"coinbase":"0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x00",
"gasLimit":"0xfffffff" }
初始化
(1)在终端输入这两条命令,创建文件夹myPrivate,并进入该文件夹
mkdir myPrivate
cd myPrivate
(2)将刚刚的创世块文件genesis.json,放在文件夹下,接着执行命令进行初始化
geth init genesis.json
启动私有链
执行如下命令:
geth --rpc --rpccorsdomain "*" --rpcapi "personal,web3,eth" console
这是我总结的最重要的geth启动项,在区块链的前端开发中每一个都不可缺少。
$ geth --rpc --rpccorsdomain "*" --rpcapi "personal,web3,eth" --rpc
addr "10.18.25.15" console
INFO [06-13|10:45:13] instance:Geth/v1.6.0-unstable-105b37f1/darwin/go1.8
INFO [06-13|10:45:13] Allocated cache and file handles database=/Users/xue/Library/Ethereum/geth/chaindata cach
e=128 handles=1024
INFO [06-13|10:45:13] Initialised chain configuration config="{ChainID: 0 Homestead: <nil> DAO: <nil> DAOSuppo
rt: false EIP150: <nil> EIP155: <nil> EIP158: <nil>}"
INFO [06-13|10:45:13] Disk storage enabled for ethash caches dir=/Users/xue/Library/Ethereum/geth/ethash count=3
INFO [06-13|10:45:13] Disk storage enabled for ethash DAGs dir=/Users/xue/.ethash count=2
INFO [06-13|10:45:13] Initialising Ethereum protocol versions="[63 62]" network=1
INFO [06-13|10:45:13] Loaded most recent local header number=288 hash=9a47c9…e52fea td=38712958
INFO [06-13|10:45:13] Loaded most recent local full block number=288 hash=9a47c9…e52fea td=38712958
INFO [06-13|10:45:13] Loaded most recent local fast block number=288 hash=9a47c9…e52fea td=38712958
INFO [06-13|10:45:13] Starting P2P networking
INFO [06-13|10:45:15] RLPx listener up self=enode://c0aa55a66963bc5321dd6633d029e3259458e68a2de
a591baee5b0bb96e1194ec7eea9bfd5fc2eaee518bfc58ed2c475a4574e9dae7a569625c6c88d89140ec7@[::]:30303INFO [06-13|10:45:15] IPC endpoint opened: /Users/xue/Library/Ethereum/geth.ipc
INFO [06-13|10:45:15] HTTP endpoint opened: http://10.18.25.15:8545
Welcome to the Geth JavaScript console!
instance: Geth/v1.6.0-unstable-105b37f1/darwin/go1.8
coinbase: 0xaae168cfde121cbbb2ceb3c7157f81a7dae82964
at block: 288 (Mon, 12 Jun 2017 12:37:45 CST)
datadir: /Users/xue/Library/Ethereum
modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
>