Although there are a considerable amount of references available on establishing a public network using Ethereum, there's quite a few concerning private networks.
Some of the important points to be noted are,
Step 2 - Launch geth
Step 4 - Setting the Etherbase
eth.accounts
Some of the important points to be noted are,
- The network Id should be any other value than 1. 1 is the default networkId of the main network. So when the networkId is different your nodes will not connect to the main network, thereby creating an isolated, private network.
- You can either pregenerate or mine your own ether.
- Should have a custom genesis file.
- Should have a separate custom data directory for the nodes.
- Node Discovery should be disabled. This is so that the node is not discoverable by people who do not add you manually. If not, your node may get added to an unknown blockchain having the same networkId and genesis block.
Step 1 - Custom genesis file
The protocol validates if the blockchains on two nodes has the same genesis file in order to identify if its the same blockchain. If it is different they cannot agree on your blockchain.
Step 2 - Launch geth
- Before launching geth, you need to define a data directory inside the same directory you have the genesis file. This is where all the blockchain data will be saved.
geth --identity "Node1" --rpc --rpcport "8080" --rpccorsdomain "*" --datadir "TestChain" --port "30303" --nodiscover --rpcapi "db,eth,net,web3" --networkid 1999
Now the genesis block will be initialized. Whenever we are using the geth command the previous custom flags should be used as below. Otherwise it will not remember.
geth --identity "Node1" --rpc --rpcport "8080" --rpccorsdomain "*" --datadir "TestChain" --port "30303" --nodiscover --rpcapi "db,eth,net,web3" --networkid 1999 console
If you need to access the geth console in a different terminal, it should be attached by giving geth attach. If it gives an error as below, path to the geth.ipc should be given. This should be inside the data directory specified.
Step 3 - Creating a new account on the Testnet
Create an account by giving the following command in the console.
personal.newAccount("123")
123 can be replaced with your own password for the account.
Purpose of this account is to set this as the account that receives the mining rewards. In order to do that we have to set it as the etherbase.
Step 4 - Setting the Etherbase
The account we created before should be now set as the etherbase. For that first check which element it is in the accounts list by retrieving all the accounts.
You can retrieve all the accounts by giving,
eth.accounts
Since it is the 0th account, it can be given as follows.
miner.setEtherbase(personal.listAccounts[0])
Step 5 - Mine test Ether
Give the following command to start mining ether.
miner.start()
Step 6 - Adding the account to Genesis File
The following line should be added under the genesis file.
"0x45e0aa3792e3d6c44521e10cd862fb9b830ff78c" : { "balance": "20000000000000000000" }
replacing the account number with yours.
The balance added in order to preallocate ether to the account.
After this rerun your geth private chain command. And get the accounts list and check if your account has been added.
geth account list
Comments
Post a Comment