Setting up genesis block: The first block (block zero) of the block chain is called as the genesis block. This is the only block on the network that doesn't point to the predecessor block. By default the genesis block is hard coded into Ethereum clients. However as we are setting up our own test network, this step is essential. All subsequent blocks will be referencing this genesis block. On Geth client, this is achieved by setting up a json file (say mygenesis.json) with the following values. Ensure this file is added to both the instances that will be running Geth (as Ethereum consensus algorithm ensures no other node will agree with your version of blockchain unless they have the same genesis block). To understand what each of these params mean please refer to this answer on stack exchange.
{
"alloc": {},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x20000",
"extraData" : "",
"gasLimit" : "0x2fefd8",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00"
}
Running geth init: Initialize the geth terminal with our genesis blockchain file.
mygenesis.json: The json file to be used for configuring the Ethereum node.
$ geth --datadir="ethdata" init mygenesis.json
Launch a geth console: Run geth in console mode and create a new account to fill some ether into it. Please ensure to run the geth console under a new --networkid, ensure the networkid is a random number sufficiently large (to avoid clashes with others). Also run the new node with the option --nodiscover which will prevent any untoward handshake from other ethereum nodes. ethdata is a directory in the current folder from where I am executing the geth command. This is the location where the blockchain data will be stored.
Create a new account: A new account can be created from the console using the command personal.newAccount("password")
$ geth --datadir="ethdata" --networkid 65535 --nodiscover console
I0326 11:36:47.028672 node/config.go:445] Failed to start Ledger hub, disabling: libusb: unknown error [code -99]
I0326 11:36:47.028882 cmd/utils/flags.go:613] WARNING: No etherbase set and no accounts found as default
I0326 11:36:47.028970 ethdb/database.go:83] Allotted 128MB cache and 1024 file handles to /home/ubuntu/ethdata/geth/chaindata
I0326 11:36:47.047079 ethdb/database.go:176] closed db:/home/ubuntu/ethdata/geth/chaindata
I0326 11:36:47.047475 node/node.go:176] instance: Geth/v1.5.9-stable/linux/go1.8
I0326 11:36:47.047573 ethdb/database.go:83] Allotted 128MB cache and 1024 file handles to /home/ubuntu/ethdata/geth/chaindata
I0326 11:36:47.078045 eth/backend.go:187] Protocol Versions: [63 62], Network Id: 65535
I0326 11:36:47.078398 eth/backend.go:215] Chain config: {ChainID: 0 Homestead: <nil> DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: <nil> EIP158: <nil>}
I0326 11:36:47.079106 core/blockchain.go:219] Last header: #0 [62e3c23e…] TD=131072
I0326 11:36:47.079187 core/blockchain.go:220] Last block: #0 [62e3c23e…] TD=131072
I0326 11:36:47.079279 core/blockchain.go:221] Fast block: #0 [62e3c23e…] TD=131072
I0326 11:36:47.081285 p2p/server.go:340] Starting Server
I0326 11:36:47.106873 p2p/server.go:608] Listening on [::]:30303
I0326 11:36:47.107290 node/node.go:341] IPC endpoint opened: /home/ubuntu/ethdata/geth.ipc
Welcome to the Geth JavaScript console!
instance: Geth/v1.5.9-stable/linux/go1.8
modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
> personal.newAccount("testing")
"0xe94c3a6c176af3f091d3cc40ba35efa96a8df444"
> I0326 11:37:21.218308 cmd/geth/main.go:286] New wallet appeared: keystore:///home/ubuntu/ethdata/keystore/UTC--2017-03-26T11-37-20.112555465Z--e94c3a6c176af3f091d3cc40ba35efa96a8df444, Locked
Start mining ether to that account: Any operation on Ethereum is possible only if you have ether (the currency used in Ethereum blockchain). When you setup a test network, you will need to mine some money into the accounts, otherwise you wont be able to perform any operations. Mining is done by the command miner.start(). This command will take sometime to execute and and accumulate ether into the previously created account.
> miner.start(1)
true
Determine the enode value of the present ethereum node: enode is a url that's used by each node within an ethereum network to perform peer-peer handshake. The enode of an ethereum node can be determined by the command admin.nodeInfo.enode. The [::] from the returned string must be replaced by your external ip address (If you running within LAN, please substitute this with your internal IP).
> admin.nodeInfo.enode
"enode://dce52ff84d904d3a304c0977fbc01efd59c2f62ceb3ebcae16044768d15282a5b411f5774e7410da26648c55a1e9d5326ecc635fb2ad73ad5569cf9df41f1e1a@[::]:30303?discport=0"
>
Launch the second AWS instance and setup the genesis block again on the instance using geth init.
Launch geth console on the second AWS instance. Ensure to provide the same networkid that you had provided in the first terminal.
Once the geth console has started, you will need to execute the addPeer command in order to establish a handshake between the two nodes.
>admin.addPeer("enode://90b7cbbaee94ab6e5bc7c5e8080bf8e2dfed5047b7c19ac61ee82511bef40faf9be2066258228ce7a71ab97b508dbef3c8f50fcf31dedfd43f2f0abd7f618db9@172.129.23.46:30303?discport=0")
true
>
You will now notice that a handshake has been established between both the nodes. This can be cross verified using the command admin.peers, which would list all the nodes within the network.
Commands such as net.peerCount will list the total number of peers within the ethereum network.
Documented full process here: http://iotbl.blogspot.in/2017/03/setting-up-private-ethereum-testnet.html
192.168.1.2]:30301
Maybe we remove that ending bracket. 2. It happened to me often that the node has the port firewalled, check that. and 3. make sure to tellgeth
using the--port
option your listening port.