搭建以太坊私链

搭建以太坊私链,第1张

概述1.下载安装git,因为需要下载克隆代码(方便). 命令:yum -y install git 2.下载安装go语言环境,因为需要使用go语言编译geth. 命令1:wget https://dl.google.com/go/go1.12.1.linux-amd64.tar.gz 命令2:tar -xzf go1.12.1.linux-amd64.tar.gz 命令3:vi /etc/profil

1.下载安装git,因为需要下载克隆代码(方便).
命令:yum -y install git
2.下载安装go语言环境,因为需要使用go语言编译geth.
命令1:wget https://dl.Google.com/go/go1.12.1.linux-amd64.tar.gz
命令2:tar -xzf go1.12.1.linux-amd64.tar.gz
命令3:vi /etc/profile 添加环境变量:export PATH=$PATH:/usr/local/software/go/go/bin
命令4:source /etc/profile
3.下载安装geth.
命令1:git clone https://github.com/ethereum/go-ethereum.git
命令2:cd go-ethereum
命令3:git checkout release/1.8
命令4:make geth,执行此命令时报错(不报错直接略过)exec: "gcc": executable file not found in $PATH,是由于没有gcc引起的,直接安装即可,命令:yum -y install gcc,然后再执行make geth.
命令5:vi /etc/profile 添加环境变量:export PATH=$PATH:/usr/local/software/go/go/bin
命令6:source /etc/profile 添加环境变量:export PATH=$PATH:/usr/local/software/go_project/go-ethereum/build/bin
4.创建私链.
1.创建genesis.Json文件,以初始化创世区块.
内容:{
"config": {
"chainID": 999,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x20000",
"exTradata" : "0xe998bfe58b87e79a84e7a781e993be2d31",
"gaslimit" : "0x2fefd8",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"alloc" : {}
}
2.执行命令:geth init ./genesis.Json --datadir "./private_chain_data"
INFO [03-31|02:24:14.518] Maximum peer count ETH=25 LES=0 total=25
INFO [03-31|02:24:14.518] Allocated cache and file handles database=/usr/local/software/go_project/private_chain_data/geth/chaindata cache=16 handles=16
INFO [03-31|02:24:14.523] Writing custom genesis block
INFO [03-31|02:24:14.523] Persisted trIE from memory database nodes=0 size=0.00B time=8.173µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [03-31|02:24:14.523] Successfully wrote genesis state database=chaindata hash=81b93d…4671a7
INFO [03-31|02:24:14.523] Allocated cache and file handles database=/usr/local/software/go_project/private_chain_data/geth/lightchaindata cache=16 handles=16
INFO [03-31|02:24:14.527] Writing custom genesis block
INFO [03-31|02:24:14.527] Persisted trIE from memory database nodes=0 size=0.00B time=2.077µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [03-31|02:24:14.527] Successfully wrote genesis state database=lightchaindata
5.启动私链.切勿直接使用geth命令,因为存在默认配置,这样会直接启动公网节点,会同步巨大的公网区块.
命令:nohup geth --datadir "./private_chain_data" --rpc --rpccorsdomain "*" --rpcaddr 0.0.0.0 --rpcAPI "eth,net,web3,personal,admin,shh,txpool,deBUG,miner" --ws --wsaddr 0.0.0.0 --wsorigins "*" --nodiscover --networkID 999 --verbosity 4 > private_chain.out &
DEBUG[03-31|02:45:30.066] Sanitizing Go‘s GC trigger percent=100
INFO [03-31|02:45:30.068] Maximum peer count ETH=25 LES=0 total=25
DEBUG[03-31|02:45:30.068] FS scan times List=48.399µs set=1.717µs diff=3.902µs
INFO [03-31|02:45:30.069] Starting peer-to-peer node instance=Geth/v1.8.23-stable-c9427004/linux-amd64/go1.12.1
INFO [03-31|02:45:30.069] Allocated cache and file handles database=/usr/local/software/go_project/private_chain_data/geth/chaindata cache=512 handles=2048
INFO [03-31|02:45:30.079] Initialised chain configuration config="{ChainID: 999 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: 0 EIP158: 0 Byzantium: <nil> Constantinople: <nil> ConstantinopleFix: <nil> Engine: unkNown}"
INFO [03-31|02:45:30.079] disk storage enabled for ethash caches dir=/usr/local/software/go_project/private_chain_data/geth/ethash count=3
INFO [03-31|02:45:30.079] disk storage enabled for ethash DAGs dir=/root/.ethash count=2
INFO [03-31|02:45:30.079] Initialising Ethereum protocol versions="[63 62]" network=999
INFO [03-31|02:45:30.124] Loaded most recent local header number=0 hash=81b93d…4671a7 td=131072 age=49y11mo2w
INFO [03-31|02:45:30.125] Loaded most recent local full block number=0 hash=81b93d…4671a7 td=131072 age=49y11mo2w
INFO [03-31|02:45:30.125] Loaded most recent local fast block number=0 hash=81b93d…4671a7 td=131072 age=49y11mo2w
DEBUG[03-31|02:45:30.125] Reinjecting stale transactions count=0
INFO [03-31|02:45:30.125] Regenerated local transaction journal transactions=0 accounts=0
DEBUG[03-31|02:45:30.125] Recalculated downloader QoS values rtt=20s confIDence=1.000 ttl=1m0s
DEBUG[03-31|02:45:30.135] InProc registered namespace=admin
DEBUG[03-31|02:45:30.135] InProc registered namespace=admin
DEBUG[03-31|02:45:30.135] InProc registered namespace=deBUG
DEBUG[03-31|02:45:30.135] InProc registered namespace=deBUG
DEBUG[03-31|02:45:30.135] InProc registered namespace=web3
DEBUG[03-31|02:45:30.135] TCP Listener up addr=[::]:30303
DEBUG[03-31|02:45:30.135] InProc registered namespace=eth
DEBUG[03-31|02:45:30.135] InProc registered namespace=eth
DEBUG[03-31|02:45:30.135] InProc registered namespace=eth
DEBUG[03-31|02:45:30.135] InProc registered namespace=txpool
DEBUG[03-31|02:45:30.135] InProc registered namespace=deBUG
DEBUG[03-31|02:45:30.135] InProc registered namespace=deBUG
DEBUG[03-31|02:45:30.135] InProc registered namespace=eth
DEBUG[03-31|02:45:30.135] InProc registered namespace=personal
DEBUG[03-31|02:45:30.135] InProc registered namespace=eth
DEBUG[03-31|02:45:30.135] InProc registered namespace=ethash
DEBUG[03-31|02:45:30.135] InProc registered namespace=eth
DEBUG[03-31|02:45:30.135] InProc registered namespace=eth
DEBUG[03-31|02:45:30.135] InProc registered namespace=eth
DEBUG[03-31|02:45:30.135] InProc registered namespace=miner
DEBUG[03-31|02:45:30.136] InProc registered namespace=eth
DEBUG[03-31|02:45:30.136] InProc registered namespace=admin
DEBUG[03-31|02:45:30.136] InProc registered namespace=deBUG
DEBUG[03-31|02:45:30.136] InProc registered namespace=deBUG
INFO [03-31|02:45:30.136] New local node record seq=1 ID=6410229f5c68e9d7 ip=127.0.0.1 udp=0 tcp=30303
INFO [03-31|02:45:30.136] Started P2P networking self="enode://7373464c88cbff3d5f963cc97322eea3d01bb51965b78b920f7bd5b417c59907a[email protected]127.0.0.1:30303?discport=0" DEBUG[03-31|02:45:30.136] InProc registered namespace=net DEBUG[03-31|02:45:30.136] IPC registered namespace=admin DEBUG[03-31|02:45:30.136] IPC registered namespace=admin DEBUG[03-31|02:45:30.136] IPC registered namespace=deBUG DEBUG[03-31|02:45:30.136] IPC registered namespace=deBUG DEBUG[03-31|02:45:30.136] IPC registered namespace=web3 DEBUG[03-31|02:45:30.136] IPC registered namespace=eth DEBUG[03-31|02:45:30.136] IPC registered namespace=eth DEBUG[03-31|02:45:30.136] IPC registered namespace=eth DEBUG[03-31|02:45:30.136] IPC registered namespace=txpool DEBUG[03-31|02:45:30.136] IPC registered namespace=deBUG DEBUG[03-31|02:45:30.136] IPC registered namespace=deBUG DEBUG[03-31|02:45:30.136] IPC registered namespace=eth DEBUG[03-31|02:45:30.136] IPC registered namespace=personal DEBUG[03-31|02:45:30.136] IPC registered namespace=eth DEBUG[03-31|02:45:30.136] IPC registered namespace=ethash DEBUG[03-31|02:45:30.136] IPC registered namespace=eth DEBUG[03-31|02:45:30.136] IPC registered namespace=eth DEBUG[03-31|02:45:30.136] IPC registered namespace=eth DEBUG[03-31|02:45:30.136] IPC registered namespace=miner DEBUG[03-31|02:45:30.136] IPC registered namespace=eth DEBUG[03-31|02:45:30.136] IPC registered namespace=admin DEBUG[03-31|02:45:30.136] IPC registered namespace=deBUG DEBUG[03-31|02:45:30.136] IPC registered namespace=deBUG DEBUG[03-31|02:45:30.136] IPC registered namespace=net INFO [03-31|02:45:30.137] IPC endpoint opened url=/usr/local/software/go_project/private_chain_data/geth.ipc DEBUG[03-31|02:45:30.137] http registered namespace=admin DEBUG[03-31|02:45:30.137] http registered namespace=admin DEBUG[03-31|02:45:30.137] http registered namespace=deBUG DEBUG[03-31|02:45:30.137] http registered namespace=deBUG DEBUG[03-31|02:45:30.137] http registered namespace=web3 DEBUG[03-31|02:45:30.137] http registered namespace=eth DEBUG[03-31|02:45:30.137] http registered namespace=eth DEBUG[03-31|02:45:30.137] http registered namespace=eth DEBUG[03-31|02:45:30.137] http registered namespace=txpool DEBUG[03-31|02:45:30.137] http registered namespace=deBUG DEBUG[03-31|02:45:30.137] http registered namespace=deBUG DEBUG[03-31|02:45:30.137] http registered namespace=eth DEBUG[03-31|02:45:30.137] http registered namespace=personal DEBUG[03-31|02:45:30.137] http registered namespace=eth DEBUG[03-31|02:45:30.137] http registered namespace=eth DEBUG[03-31|02:45:30.137] http registered namespace=eth DEBUG[03-31|02:45:30.137] http registered namespace=eth DEBUG[03-31|02:45:30.137] http registered namespace=miner DEBUG[03-31|02:45:30.137] http registered namespace=eth DEBUG[03-31|02:45:30.137] http registered namespace=admin DEBUG[03-31|02:45:30.137] http registered namespace=deBUG DEBUG[03-31|02:45:30.137] http registered namespace=deBUG DEBUG[03-31|02:45:30.137] http registered namespace=net INFO [03-31|02:45:30.137] http endpoint opened url=http://0.0.0.0:8545 cors=* vhosts=localhost DEBUG[03-31|02:45:30.137] WebSocket registered service=&{stack:0xc0001d8780} namespace=web3 DEBUG[03-31|02:45:30.137] WebSocket registered service=&{b:0xc0004a4a50} namespace=eth DEBUG[03-31|02:45:30.137] WebSocket registered service=&{b:0xc0004a4a50} namespace=eth DEBUG[03-31|02:45:30.138] WebSocket registered service="&{b:0xc0004a4a50 nonceLock:0xc0004a5000}" namespace=eth DEBUG[03-31|02:45:30.138] WebSocket registered service=&{am:0xc0000a7450} namespace=eth DEBUG[03-31|02:45:30.138] WebSocket registered service=&{ethash:0xc000258a80} namespace=eth DEBUG[03-31|02:45:30.138] WebSocket registered service=&{e:0xc000258b60} namespace=eth DEBUG[03-31|02:45:30.138] WebSocket registered service=&{e:0xc000258b60} namespace=eth DEBUG[03-31|02:45:30.138] WebSocket registered service="&{d:0xc000034340 mux:0xc0001bdec0 installSyncSubscription:0xc0004610e0 uninstallSyncSubscription:0xc000461140}" namespace=eth DEBUG[03-31|02:45:30.138] WebSocket registered service="&{backend:0xc0004a4a50 mux:0xc0001bdec0 quit:<nil> chainDb:0xc0000d8370 events:0xc0000cb680 filtersMu:{state:0 sema:0} filters:map[]}" namespace=eth DEBUG[03-31|02:45:30.138] WebSocket registered service="&{net:0xc0001d8a00 networkVersion:999}" namespace=net DEBUG[03-31|02:45:30.138] Allowed origin(s) for WS RPC interface [*] 命令:geth attach ./private_chain_data/geth.ipc 进入控制台模式6.创建账户,启动挖矿 命令1:personal.newAccount(‘ay123456‘) 返回0x043349c7b7d4514fc1525f6292ca90466522569e 命令2:miner.start() 启动挖矿 命令3:miner.stop() 停止挖矿

总结

以上是内存溢出为你收集整理的搭建以太坊私链全部内容,希望文章能够帮你解决搭建以太坊私链所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/1031951.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存