以太坊geth私链安装配置详细步骤.pdf
以太坊geth私链安装配置详细步骤,包括应用安装配置、创建私链、基本操作命令等内容。tI@sl: -/ethereums ge-h-hNAMEeth -the go-ethereum command line interfaceCopyright 2013-2018 The go-ethereum AuthorsUSAGE:geth [options] command [command options] [argunents..VERSION1.8.12- stable-37685939coMManDSaccountanage accountsattachStart an interactive JavaScr-pt environment connect to node)bugopens a window to report a bug on the geth repoconsoletart an interactive Javascr-pt environmentcopydbCreate a local chain from a target chaindata folderdumpDump a specific block from storageShow configuration valuesexportExport blockchain into fileexport-preimages Export the preimage database into an RLP streamImport a blockchain fileimport-prcimages Import the preimage database fron an rlp streamootstrap and initialize a new genesis block2.创建geth私链2.1.创世块文件创建私链需要定义创世块文件,这个文件用来创建区块链的创世区块。本文创世块文件 myogeneSis.json如下myogeneSis.JsonconfhomesteadBlock. 0cipl55block: 0eip158Block: 0" coinbase":"0x000000000000000000000,0difficult0x2000,extraData0x54686973206973206d7920666972737420457468657265756d20426c6f636b636861696e21gaslimit: Oxffffffff" nonce":"0x0000000002,"0x00000000000000000000000000000000000000000000000000000000″parenthash0x00000000000000000000000000000000000000timestamp:0x00aI⊥oC具体内容说明可以参考百度其它文章,本文不在赘叙。2.2.创建创世块执行下面命令初始化创世块:geth --datadir./myblockchain init my genesis json屏幕输出:1@s1: /ethereum cat mygenesis jsonconl igchained: 168homesteadBlock: 0cipl5sblock: 0eipl58Block": ononbase0x000000000000000000000000000000000difficulty0x4000extruDate0x54686973206973206d792066972737420457468657265756420426c6f636b636861696e21gasLimit: Oxffffffffnonce":"0x00000000002″,mihashi0x00000000000000000000000000000000000000000000000parentHash0x000000000000000000000000000000000000000000t imes tampallocItl@sl:/ethereum$ gethdatadir/myblockchaininitmy genesis jsonWARN [O7-26 19: 06: 57. 512] Sanitizing cache to Go's GC limitsprovided=1024 updated=664INFO[07-2619:06:57.548MaximumpccrcountETH=25 LES=0 total=25NFO[07-2619:06:57.597cache and file handlesdatabase-/home/t1/ethereum/myblockchain/geth/ chaindatacache=16handles=16NFO [O7-26 19: 06: 57. 646 Writing cus tom genesis blockINFO [07-26 19: 06: 57. 646] Persisted trie from memory databasenodes=0 size=0. 00B time=4. 082As gcnodes=0 gcsize=0. 00B ctime=Oslivenodes-1 livesize-0. 00BINFO [07-26 19: 06: 57. 646] Successfully wrote genesis stateldatabase=chaindatahash=fd1450…5a95b5INFO [07-26 19: 06: 57. 646] Allocated cache and file handlesdatabase-/home/t1/ethereum/myblockchain/geth/lightchaindata cache-16handles=16INFO [07-26 19: 06: 57 659] Writing custom genesis blockINFO [07-26 19: 06: 57 659] Persisted trie from memory databasenodes=0 size=0. 00B time=2.004us gcnodes=0 gcsize-=0. 00B gctime-=0sivenodes=1 linesize=0. OOBINFO [07-26 19:06: 57 659] Successfully wrote genesis stateldatabase=lightchaindataash-fd1450…5a95b5Itl@sl:/ethereum$输出截屏Isl: -/ethereums cat myogenesis. ]son"config":tmi xhashallow[07-26 19: D5: 57 5971 AL located cache and file handledatabase=/home/t1/ethereum/'myblockchain/geth/chaindata cache=16 handles6119: B5: 57.6461 Persisted trie from memory databasnodes=0 size=B, eeB timea. 882us ocnodes=0 gcsizer0 008 ctime=es L:veno[07.26 19: 05: 57 G46] Successfully wrote genesis stateash=fd1450.5a95[07- 26 19: 05: 57.6461 ALlocated cache and file handlesdatabase=/home/t1ethereum/myblockchain/geth/lightchaindata cache=16 harom nemory databasenodes=0 size=0. coB time=2. 004us gcnodes=0 gcsize=0. 008 ctime=os L:veno[. 19: 05: 57 659) SuccessfuLly wrote genesis statedatabasezlightchaindatahash=td1450初始化结束后,当前日录会新建日录 myblockchain, myblockchain旧录下多了geth和 keystore两个文件夹:1)geth保存的该链上的区块数据2) keystore保存的该链上的用户信息日录结构如下NIFEST. 060080directories, 11 files2.3.启动私链启动私链geth --identity"Myethereum" -rpc --rpcaddr 192 168.3. 192rpcport"8545″rpccorsdomain *"--datadir. /myblockchain --rpcapidb, eth, net, web3, admin, personal"--networkid 666 console这里简单介绍一下geth的一些参数,详细说明找度娘参数名描述identity区块链的标示,用于标示目前网络的名字inl t指定创世块文件的位置,并创建创世块datadir当前区块数据存放的位置port网络监听端口,默认30303rpc启动rpc通frpcapI设置允许连接rpc的客户端,一般为db,eth,net,wcb3cor)2什么ul能在到你的节执rc制端什务如果铂疋urrpcrpcaddr连接rpe的地址,默认为 localhost,为了方便访问建议使用本机IP地址report连接rpc的端口,默认为8545设置当前区块链的网终ID,用于区分不同的网终,是一个数networked‖字,共链为1;这个和创世块文件的 chained没有直接关联,这很多文章都误会了console启动命令行模式,可以在geth中执行命令屏幕输出:t1@s1:/ethereumS geth -identity "Myethereumrpcrpcaddr192.168.3.192″report"8545′rpccorsdomain"Ndatadir/myblockchain --rpcapi"db,eth, net, web3, admin, personalnetworked 666 consoleWARN [07-26 19: 14: 04. 592] Sanitizing cache to Go's GC limitsprovided-=1021 updated-=664INFO [O7-26 19: 14: 04.597] Maximum peer countETH=25 LES=0 total=25INFO [07-26 19: 14: 04. 600] Starting peer-to-peer nodeinstance=Geth/ Myethereum/v1.8. 12-stable-37685930/linux amd64/gol. 10INFO [O7-26 19: 14: 01. 600 Allocated cache and file handlesdatabase=/home/t1/ethereum/myblockchain/geth/chaindata cache=498handles=512INFO [07-26 19: 14: 06. 718] Initialised chain configurationIconfig="ChainID: 168 Homestead: 0 DAO: DAOSupport: falseEIP150:EIP155: 0 ElP158: 0 Byzantium: ConstantinopleKnil> Engine: unknown)INFO [O7-26 19: 14: 06.718] Disk storage enabled for ethash cachesdir-/home/t1/ethereum/myblockchain/geth/cthash count-3INFO [O7-26 19: 14:06. 719] Disk storage enabled for ethash DAGsdir=/home/t1/.ethashcountINFO [O7-26 19: 14: 06. 719] Initialising Ethereum protocolversions="[63 62] network=666INFO [07-26 19: 14: 06. 719] Loaded most recent local headernumber=0 hash=fd1450-5a95b5 td=16384INFO [07-26 19: 14: 06. 719] Loaded most recent local Iull blockInumber=o hash=fd1450.5a95b5 td=16384INFO [0726 19: 14: 06. 719] Loaded most recent local fast blockInumber=o hash=fd1450.5a95b5 td=16384INFO [07-26 19: 14: 06. 720] Regenerated local transaction journaltransactions=0 accountsINFO [O7-26 19: 14: 06. 740] Starting P2P networkingINFO [O7-26 19: 14: 08. 884] UDP listener upself-enode: //35963c7a89aef0112cb3e51119ca507f5ee157201c03a1952b7cc5k30a54993a3c34fb46ec543a781adal10e69c759e43c01f0894b33ab9b07477ca23ac[::]:30303INFO [O7-26 19: 14: 08. 997] IPC endpoint openedurl=/home/tl/ethereum/myblockchain/geth. ipcInFo [o7-26 19: 11:08.997] HttP endpoint openedurl=http://192.168.3.192:8545cors=k vhost s=localhostINFO [O7-26 19: 14: 09.] RLPx listener upself- enode://35963c7a89ef042cb3c51419ca507f5c157201c03a1952b7c5f230a54993a3c34b146eec543a781ada110e69c75943c01f089fb33ab9b07477ca2a:]:3030Welcome to the Geth JavaScript console!instance: Geth/ Mye thereum/v1.8. 12-stable-37685930/linux-amd64/golmodules: admin: 1.0 debug: 1.0 eth: 1.0 miner: 1.0 net: 1.0 personal: 1.0pc: 1.0 txpool: 1.0 web3:截屏:t1@sl:-/ethereums geth-identity"Myethereun"--rpc --rpcaddr"192.168.3. 192"--rpcport8545pccorsdomain"*”· datadir,/ mvblockceb3, admin, personal"--netwarkid 666 consoL(to Go's GC limitsprovided=1024 updated=664[07-25 19: 14: 04. 600] starting peer-to-peer nodenstance=Geth/Myethereum/v1. 8. 12.stable. 37685930/L1nux-amd64/go1g=tChalnID: 168 Homestead: 0 DAO: DAOSupport: false EIP150:5:9EIP158anium eniltantincple: Engine: unknownorage enablhereum/myblockchain/geth'etnash count=3Eth=6666384[07-25|19:14:08.884 I UDP list:Lf=enode: //35963c7a8gaef0442cb3e51419ca597f5ee157201ce3a1952b7cc5f23043L91f8894b3b9bG7477dd23a[::]:33instance: Geth/Myethereun/v1.8. 12-stable-37685930/Linux-amd64/gol. 10modules: admin: 1. 0 cebug: 1. 0 eth: 1.0 miner: 1.0 net: 1. c personal: 1. 0 rpc: 1. p txpool: 1.0 web3: 1.024连接第二个geth终端为了方便使用,经常要打开多个终端连接到同一个私链节点,可以采用如下命令,其中ipc就是启动私链时输出的“ i pc endpoint openedgeth attach ipc: /home/t1/ ethereum/myblockchain/geth. ipctiesi: -ene/tl/ethereum/myb lockchain/geth. 1pcunitizing cache to Go's GC linitsvided=1624 updated=664instance: Geth/Myeth1.8.12- stable-37685930/ Linux-amd64/901.10ob4c9d84ce4593797o cth: 1.0 miner: 1.e nct: 1. 0 personal: 1. 0 rpc: 1.e txpool: 1.0 wcb: 1.0eth, accountseth blockNumber3.geth创建账号、启动挖矿、停止挖矿初始化后系统无账号,需要创建新账号,才能启动挖矿:s eth. accountspersonal newAccount("123456")eth. getEalance("0xeee4836e2dc3daeab2fo934b2869b8fb1630f25d")9: 16: 09. 750] Updated mining threads16: 09, 750] Transaction pool price threshold updated price=l8000600008herbase automatically configuredaddress=exe E4836e2DC3d80AB2f9934b2869b81b1630f 25d[C7-26|19: 16: 09. 750] Starting mining operation597pd=22.18627,995spoch=0 percentage要到100,时间有点长。ed=16m18.77254.995INFo 167-26 19: 29: 08.] Generating DAG in progress=3 elapsed=2m27.9675epoch=1 percentage也要到100,时间有点长i in progre2 elapsed=46m22.6795d=4657.3015saction journalp5c=164,12m50: 43.783] Commit new mining worko eLapsed-122.173useth getBalance("0xeGe4835eZdc3d6eab2f0934b286sb8fb1530f25d")4.geth常用操作枚举系统中的账户;eth. accounts;创建账号: personal. newAccount("123456″);括号为密码查询余额eth getBalance(0xf575e2c4035c8120deddc52f04a6d998d7c84108")解锁账户; persona1. unlockAccount()挖矿: miner. start(I)停止挖矿: miner.stop交易池状态: txpool. status区块总数:cth. blocknumber;获取交易:eth. getTransaction(:获取区块:eth. getBlock(连接到其他节点 admin. addPeer(设置挖矿账户: miner. setetherbase(eth. coinbase)#设置挖矿账户转账交易,要先解锁账号:eth. sendTransaction (from: ,to: value: web3. toWei(3, ether D)eth. sendTransaction(ifrom: 0x6116a2de8456d2c8ac079de4c6374b03b4e98beato:Oxecb92861d22221d03ebelc7fo6df172c6f99f58", gas: 31000, gasPriceweb3. toWei(300,' gwei'),value": 1)personal. unlockAccount( 0x499d3d3d9a 3dfe802f5b23d38543a860de186b3d123456″,1000*60*120)personal. unlockAccount("0x06a71be1d29dOf6b7bf6991 ded7b9acdecf56cdo123456″,100060米120)personal. unlockAccount( Oxf89478188a9a0c9646bad16091d548a998ed4682123456",1000米60*120)eth getBalance(0x499d3d3d9a3dfe802f5b23d38543a860de186b3d")eth getBalance(0x06a74beld29dof6b7b16991ded")eth getBalance( Oxf89478188a9a0c9646bad16091d548a998ed4682")cth. sendTransaction(from: 0x499d3d3d9a3dfc802f5b23d38543a860de186b3d0x06'a74beld29d0f6b7bf6991ded7b9acdecf56cdo, value: web3. toWei(100, ether")})cth. sendTransaction(from: 0x499d8d8d9a3dfe802f5b23d38543a860dc186b3d0x89478188a9a0c9646bad16091d548a998ed4682", value:web3. toWei(100,"ether5.转账操作和区块数据5.1.转账交易操作和过程leth. ge bAlance ("0x499d3d3d9a3dfe80215b23d38543a860de186b3leth getBalance("0x06a74be1d29dOf6b7bf6991ded7b9acdecf56cdoleth getBalance("0xf89478188a9a0c9646bad16091d548a998ed4682")Itxpool statulleth. sendTransaction(ffrom: 0x06a74be1d29d0f6b7bf6991ded7b9acdecf56ceto:"0x89478188a9a0c9646badl6091d548a998ed4682",vaue:web3. toWei(3,ether")s)
下载地址
用户评论