How to Create Private Ethereum Blockchain
How to Create Private Ethereum Blockchain
In the article we will describe how to start Ethereum private blockchain with Geth, and also touch on the mechanics of Ethereum private networks.
Ethereum private network is a private blockchain completely isolated from the main Ethereum network. Typically, private networks are created by organizations to store personal data that should not be visible to people outside the organization. In addition, the private network Ethereum can be used for testing and experiments with the blockchain.
Features of private Ethereum blockchain:
To start a private blockchain, your computer must become a node in the Ethereum network, that is, you need to download the entire blockchain network and synchronize it with the main chain of Ethereum. We can use various tools (client) for this, but we need those that allow us to interact with the blockchain network:
The client can be downloaded from geth.ethereum.org. There are builds for Ubuntu (Linux family), OS X (Apple devices), Windows and even Android. Instructions on what to do after downloading the distribution kit are located in the «Install» section (be sure to read and do everything written there).
After we have installed and synchronized Geth with Ethereum, we can start the launch of a “private” or “test” network. This is the best way to learn blockchain technologies, as you can create, deploy and test smart contracts and decentralized applications within the Ethereum private network without spending a single live ether. Moreover, you can create a “fake” ether and use it to carry out a transaction and initialize smart contracts.
When running your own blockchain, it is strongly recommended to use a separate folder for storing data (database and wallet) of a private network. This is necessary for Ethereum private network files. Do not replace files with a public one.
To do this, do the following:
1. Create an empty folder on your desktop. For example, with the name PrviaceChain3.
2. Right-click on the created folder and select «Git Bash Here».
3. If everything is ok, the system will show the following.
To create a private blockchain, you first need to generate a genesis block. To do this, you need to create a Genesis file, write the necessary commands (attributes) into it and use it with Geth.
Here are the commands you need to register in the Genesis file:
And this is what the attributes specified in it mean:
After creating the Genesis file, open Geth and enter the following command:
This command instructs Geth to use the CustomGenesis.json file we previously created to generate the first block of the private blockchain Ethereum. The “path_to_folder” attribute is the folder where you saved the Genesis file. Whereas the attribute “path_to_your_data_directory” indicates the folder in which the data of our private chain will be stored (created in the first step).
When you run the specified attribute, you will see how Geth connects to the Genesis file and provides confirmation of the successful completion of the action. It will look like this:
So, we have created a genesis block. Now you can run our private network so that we or other nodes (if you created several) can add new blocks. To do this, in the Geth console, you need to initiate the command:
This command instructs Geth to launch a private blockchain. And use the specified directory ("path_to_your_data_directory" replace the address of the desired folder) to access the running network.
The command also has the identifier "7776". It should be replaced with an arbitrary number that is not equal to the identifier of the networks already created, for example, the identifier of the main network Ethereum ("networkid = 1"). The identifier "networkid = 7776" also should not be used, otherwise you will connect to the network we have created for this guide.
Here is a list of identifiers of the existing Ethereum blockchain networks:
When you initiate the specified command with YOUR identifier, you start your blockchain's private network. This is what the Geth terminal will show after successfully executing the command:
Another important point. Geth does not remember the parameters of your private blockchain network, so every time you want to access your private chain, you will need to run commands in the console that initiate a connection to the Genesis file and your private network. Keep them handy so you don’t look for them every time.
These two teams:
If everything is done correctly, by this moment you will have a personal blockchain and a private Ethereum network. And now you can begin to interact with this chain.
This will connect the second window to the terminal of the first window (make sure it really happened - it all worked). If everything is correct, the terminal will display the following:
If the image on your terminal matches the screenshot in the instructions, you can create an account. To do this, in the second window enter the command:
Next you will be asked to set a password, the introduction of which initiates the creation of an account. It looks like this.
Save the created account (a long set of characters in the screenshot), as you will use it often. In addition, save the passphrase because it will be needed every time you connect to your account.
Next, we need to check the balance status of the account (how much ether is there). To do this, use the following command:
That's what you should do:
Account balance must be zero. This is correct, because when starting a private network in the genesis file, we did not specify anything in the alloc attribute. You can replenish the balance now in two ways: either someone will send you a little ether, or you will receive a reward for creating a new unit. And since you are now the only member of your private network, you have in fact, no choice.
Mining on the main chain of Ethereum (real) is complex and requires expensive equipment with powerful graphics processors. Usually ASICs are used for this. However, for the mining of coins of our chain, any device will be suitable, since in the genesis file we set the mining difficulty low (difficulty attribute). In other words, we can start mining just by using the following command:
The result should be:
If you use the eth.getBalance command in the second Geth window, you will see how the balance of your account is replenished with a fake ether. The speed of mining will be very high, so you can become a multimillionaire in just a couple of seconds.
When there is enough money, use the following command to stop mining:
And remember that this is a fake ether. It can only be used within your private blockchain for testing transactions, smart contracts, decentralized applications and other functions.
You created your first private Ethereum blockchain and got some ether! Yes, this is not real money and a test network, but the experience gained can be used to launch startups or integrate blockchain technologies into your own business.
#1. What is Ethereum Private Network
#2. What is Ethereum Virtual Machine
#3. What is Geth (Go Ethereum)
#4. How to create private blockchain Ethereum
#5. Step 1: Create the DATADIR folder
#6. Step 2: Create a genesis block
#7. Step 3: Start the private network
#8. Step 4: Create an externally owned account (EOA)
#9. Step 5: Get some ether for our account
Blockchain-based digital asset platform