第一部分:搭建本地私链1. 选择合适的区块链平台以太坊私链 (推荐初学者) Hyperledger Fabric Quorum 其他支持私有网络的区块链平台
2. 以太坊私链搭建步骤安装必要软件text
# 安装Geth (Go Ethereum)sudo add-apt-repository -y ppa:ethereum/ethereumsudo apt-get updatesudo apt-get install ethereum
创建创世区块配置文件 (genesis.json)json
{ "config": { "chainId": 12345, "homesteadBlock": 0, "eip150Block": 0, "eip155Block": 0, "eip158Block": 0, "byzantiumBlock": 0, "constantinopleBlock": 0, "petersburgBlock": 0, "istanbulBlock": 0 }, "alloc": {}, "coinbase": "0x0000000000000000000000000000000000000000", "difficulty": "0x20000", "extraData": "", "gasLimit": "0x2fefd8", "nonce": "0x0000000000000042", "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp": "0x00"}
初始化私链text
geth --datadir ./privatechain init genesis.json
启动私链节点text
geth --datadir ./privatechain --networkid 12345 --nodiscover --rpc --rpcaddr 0.0.0.0 --rpcport 8545 --rpccorsdomain "*" --rpcapi "eth,net,web3,personal" --allow-insecure-unlock console
第二部分:局域网内共享服务1. 配置节点允许局域网访问2. 局域网内其他设备连接方法一:直接RPC连接其他设备可以使用web3.js或类似库连接到你的节点: javascript
const Web3 = require('web3');const web3 = new Web3('http://[你的本地IP]:8545');
方法二:添加为对等节点在第一个节点控制台获取enode信息: text
admin.nodeInfo.enode
在第二个节点启动时添加: text
geth --datadir ./privatechain2 --networkid 12345 --port 30304 --bootnodes "enode://第一个节点的enode信息@[第一个节点的IP]:30303"
3. 共享前端服务如果你有DApp前端: 4. 安全注意事项常见问题解决
|