go-ehtereum编译:

git clone https://github.com/ethereum/go-ethereum.git
cd go-ethereum && git checkout
make geth //生成的geth在build/bin/geth
git

建立私链github

一、建立文件夹来存储私链数据:web

mkdir privatechain

二、 使用geth来加载:json

geth --networkid 123 --dev --datadir data1 --rpc --rpcaddr 192.168.1.5 --rpcport 8989 --port 3000

--identity:指定节点 ID;
--rpc:表示开启 HTTP-RPC 服务;
--rpcaddr:HTTP-RPC 服务ip地址;
--rpcport:指定 HTTP-RPC 服务监听端口号(默认为 8545);
--datadir:指定区块链数据的存储位置;
--port:指定和其余节点链接所用的端口号(默认为 30303);
--nodiscover:关闭节点发现机制,防止加入有一样初始配置的陌生节点

三、 打开另个终端, 进入交互式js执行环境:api

geth attach ipc:<data1>/geth.ipc

eth:包含一些跟操做区块链相关的方法;

net:包含一些查看p2p网络状态的方法;

admin:包含一些与管理节点相关的方法;

miner:包含启动&中止挖矿的一些方法;

personal:主要包含一些管理帐户的方法;

txpool:包含一些查看交易内存池的方法;

web3:包含了以上对象,还包含一些单位换算的方法。

方法二:网络

一、 新建genesis.json文件在privatechain目录下:ide

{
  "config": {
          "chainId": 10,        //与github上仅修改此处
          "homesteadBlock": 0,
          "eip155Block": 0,
          "eip158Block": 0
      },  
  "alloc"      : {}, 
  "coinbase"   : "0x0000000000000000000000000000000000000000",
  "difficulty" : "0x20000",
  "extraData"  : "", 
  "gasLimit"   : "0x2fefd8",
  "nonce"      : "0x0000000000000042",
  "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp"  : "0x00"
}

二、 初始化,建立创世区块区块链

geth --datadir  ~/privatechain/ init  ~/privatechain/genesis.json

三、 建立私链ui

geth --datadir ~/privatechain/ --nodiscover

四、使用js交换环境:code

geth attach ipc:~/privatechain/geth.ipc

五、 新加入节点:

先操做1,2,3,4
执行:admin.addPeer("<节点信息>@ip: 30303")
返回: true

api:eth_getBalance 流程:

// ethclient/ethclient.go
相关文章
相关标签/搜索