Original address; https://blog.csdn.net/zhj_fly/article/details/79618194
Before that, a private chain must be built on a computer: link
Suppose two computers A and B have ip addresses 192.168.1.1 and 192.168.1.2 respectively
Require:
1. The two computers must be in the same network and can be pinged.
2. Both nodes use the same genesis block file
3. Disable ipc; also use the parameter --nodiscover
4. The networkid must be the same, and the port number can be different
Here both nodes use this genesis block file:
- {
- "config":{
- "chainId":15,
- "homesteadBlock":0,
- "eip155Block":0,
- "eip158Block":0
- },
- "nonce": "0x0000000000000042",
- "timestamp": "0x00",
- "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
- "extraData" : "0x00 "
- "gasLimit": "0x80000000",
- "difficulty": "0x400",
- "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
- "coinbase": "0x3333333333333333333333333333333333333333",
- "alloc": { }
- }
Node A:
geth --datadir "./" init genesis.json
geth --datadir "./" --nodiscover --networkid 333 --ipcdisable --port 1111 --rpc --rpcport 2222 console
This will enter the console interface and obtain the information of this node:
admin.nodeInfo.enode
(My return value is:
"enode://c4561d49c91090f4666969dd01b223adbe10c9eeb3d65326002099e4a9f3f17dec3d3c70c8dceffbe4438d3f5f0ee5a9a11841076063422b629be778d669c8df@[::]:1111")
Node B: Execute the same command
geth --datadir "./" init genesis.json
geth --datadir "./" --nodiscover --networkid 333 --ipcdisable --port 3333 --rpc --rpcport 4444 console
Then node B actively joins node A: (connected through A's enode information, including ip address and port number)
admin.addPeer("enode://c4561d49c91090f4666969dd01b223adbe10c9eeb3d65326002099e4a9f3f17dec3d3c70c8dceffbe4438d3f5f0ee5a9a11841076063422b629be778d669c8df@192.168.1.1:1111")
(Note: You cannot copy the above enode as it is, you need to fill in the ip address of node A)
Then test on both nodes:
net.peerCount
will return the number of other connected nodes
admin.peers
Return information about other nodes
Then one node creates an account, starts mining, and the other node automatically syncs.
(Node A can deploy the smart contract on the private chain, and node B can call the contract according to the contract deployment address)