Setup private Ethereum network

Setup private Ethereum network and solidity program

With the widespread use of Ethereum and blockchain network technology, plenty of people these days choose to set up their private Ethereum network and solidity program as it can offer them a range of important benefits. Whether one is looking to come up with a smart contract or build a personal Dapp, a private Ethereum network can be extremely beneficial in achieving such goals. A private Ethereum network can also help the users to set up their own ICOs. No matter what the goals of working with a private Ethereum network might be, it can always be helpful to learn about smart contracts and the way they work.

blooming (1)

The Ethereum platform has got huge potential to develop Dapps that can effectively change the way people interact with each other on the World Wide Web in the future. Ethereum deploys highly effective smart contracts which ultimately work like standard Blockchain transactions. They also provide with a conditional statement which has to be met before any function or functions can be executed. A smart contract can be easily used for crowdfunding, voting, multi-signature wallets, blind auctions as well as many other important functions.

Here are some of the things that you must know about when you are looking to set up a private Ethereum network.

How to set up Ethereum Node

An Ethereum node can be defined as a device which helps to run the Ethereum protocol or blockchain protocol. Although the nodes usually run on laptops and desktops, currently nodes are being built for mobile devices as well. As we connect to an Ethereum protocol to carry out our goals, we are actually on Ethereum blockchain network during the operation and running a node. Simply by running the Ethereum node, it is possible for us to connect directly to the other nodes present within the network, enjoy direct access to blockchain as well as do things such as send transactions, mine blocks as well as deploy smart contracts.

Nodes are generally written in C++, Python and Go (Go Ethereum/Geth). We will show you how to work with Go which is by far the most widely used language for Ethereum blockchain technology. You should also remember that downloading Geth gives you access to the whole of Ethereum blockchain. Before you start working with it, make sure that you have at least 35 GB storage space on your hard disk.

01

Here are the steps that you will need to follow when you want to set up Ethereum Node with Go.

  • Visit https://geth.ethereum.org/downloads/, the official Go Ethereum website to download and install the Geth program.
  • You must always download the latest version of Geth and always stick to the 64-bit version.
  • Install the program after you have downloaded it.
  • Make sure you check the Geth box before you click “Next”.
  • You will be asked to choose a destination folder to keep all downloads. The default folder selected by Geth is C:\Program Files\Geth.
  • Close the installer once you are done.
  • Open up the command prompt and navigate to Geth directory simply by typing the command “cd C:\Program Files\Geth”.
  • Finally, start syncing to Ethereum blockchain simply by typing “Geth”. As this is your very first sync, you are going to have to download the whole blockchain program from the other peers. This is going to take some time and so you need to relax and get comfortable.

Establishing your Private Ethereum Network

After you have established access to Ethereum protocol through the node, you need to set up your own private server that can help you to develop and implement your smart contract. You are not going to deploy this actually in the Ethereum blockchain but on your own blockchain. You can start simply by initializing the first block in your blockchain.

005

  • Create one new folder called “Private Chain” on your desktop.
  • Open the command prompt for this folder to create one data directory folder to accommodate chaindata simply by writing “Mkdir chaindata”.
  • Next, you will have to develop and save the Genesis block or genesis.json block in the Private Chain folder. The genesis block can be used for initializing your private network as well as for storing data in data directory folder called “chaindata”.
  • Once you are done, open up a notepad and copy and paste this code in a new file and name it “genesis.json”. Save the file in the Private Chain folder.
  • You will need to initialize your private network in chaindata directory with the help of the genesis.json file. You will need to inform Geth that you want data directory in “chaindata” directory. It is important that you notify the exact location of the genesis.json file. Do not keep genesis.json in the chaindata folder. Type the command geth –datadir=./chaindata/ init ./genesis.json in the command prompt line indicating Private Chain folder.
  • This will help you to successfully write down the genesis state.
  • We can now start Geth to get connected to the private chain. When you see geth.ipc, the endpoint socket connection and port 30303 is going to be opened.

The IPC endpoint is going to open any time we start the Geth. This can be used for processing the connections to Geth simply with the help of programs like Mist, Ethereum Wallet, MetaMask. The Geth JavaScript API system can also be opened with the help of the IPC endpoint.

Before you proceed to the next step, you need to develop some ideas about what are Mist, Ethereum Wallet and MetaMask and how can they be used for your blockchain goals.

Untitled design

Mist

Mist can be defined as an electron application that functions as desktop hybrid app equipped with web interface. With Mist, you can work on the faster development of your Mist interface as well as customize your experience with Mist browser. However, you also need to remember that Mist is currently in its beta stage which means that you can experience some issues while working with it.

The Mist program is quite powerful since it has a Geth node which can run in the background once it is launched. It helps to immediately establish a connection with the Ethereum blockchain. However, since we are working to develop a smart contract, it is important that we simply run a node in our private network instead of using Mist for connecting it to default Geth node.

MetaMask

MetaMask is a tool that functions as a wallet and an Ethereum browser. MetaMask allows you to interact with the Dapps and the smart contracts present on the web even without having to install any software or download the blockchain. All you need to do is simply add the MetaMask to the Chrome browser as an extension, develop a wallet and start depositing ether. Currently it is only available for the Chrome browser but a version is now being developed for Firefox.

Ethereum Wallet

The Ethereum Wallet functions as a Mist implementation which can only access one single Dapp, i.e. the wallet dapp. JavaScript and HTML code is used for writing the Ethereum Wallet. It also makes use of the web3.js for manage the accounts.

004

Downloading the Mist Browser and then connecting it to Private Network

  • Visit the page https://github.com/ethereum/mist/releases to download the latest version of Mist installer so that you can connect it to the private network.
  • Use the installer for installing the program.
  • Choose C:\Program Files\Mist as the default download path for the program by clicking “Next”.
  • Confirm blockchain data that is to be stored under \Roaming\Ethereum and then click “Install”.

Once you are done, open Mist and explore its features to develop a better idea for the program.

Connecting Mist to Private Network

Once you are done with these above steps, you can simply open up a command prompt line in the Private Chain folder to give the command to Geth for connecting with our datadir. This can be accomplished by the following command.

geth –datadir=./chaindata/

Geth is then going to start running and after the Mist program is started, geth.ipc endpoint is going to open; a connection with the private network will then be established by Mist. Mist must be connected with “Private-Net” that is shown in upper right-hand corner of Mist launch window.

Things to know while working with Mist

  • When you open the Mist program, you can see the tool bar right at the top. Under “Develop” tab you can navigate to the “Ethereum Node” to find that we are currently running our very own network and not connected to Geth. We can also make use of the “Developer Tools” under “Develop” tab.
  • Just on the left section of Mist browser, you can find numerous tabs that offer you access to different functions. You can open the Ethereum Wallet by simply clicking on green box. This wallet can make it really easy for you when you are looking to interact with JavaScript interface of the Go Ethereum.
  • Through https://wallet.ethereum.org/, we can get connected to Ethereum wallet and perform functions like sending ether, checking out past transactions as well as watching or deploying contracts.
  • You can check out your accounts, create wallet contracts such as single owner accounts and multi-signature wallet contracts, add new accounts, import wallets and examine all past transactions from the “Wallets” tab.

005

  • You can click on the “Add Account” and come up with a new account and then set up a safe password before you create your wallet.
  • Under “Send” tab, you can send ether easily from wallet to wallet, or from wallet to some contract. You will also have the option to set free for such a transaction. All the transactions involve some fee or gas for incentivizing the processing. The amount of fee will depend on the speed at which you want to have the transaction processed and then approved by blockchain.
  • Finally, under “Contracts” tab you can watch existing contracts, deploy new contracts as well as watch all previously created tokens.
  • You can also set the options for watching the tokens and contracts. For instance, if you are keen on interacting with some previous deployed contract, all you need to do is click on the “Watch Contracts” option and enter the contract’s name, contract address as well as the ABI or application binary interface of the contract. If you want to watch or spend the ERC-20 tokens, you can also put in the token name, token contract address and the token symbol.

Working on Solidity

If you are well acquainted with JavaScript, you must be aware of its interrelations with Solidity. Just like JavaScript, Solidity functions as a high-level contract-oriented language designed for targeting the Ethereum Virtual Machine or EVM. Its code is typed statically and it supports libraries, inheritance as well as user-defined complex types among various other features.

With our project, we are going to come up with a state variable known as a counter and then assign a specific starting value. We’re then going to come up with a function which can increase the state variable simply by 1. The first code that we are going to type is the main source code version. While writing the code, it is very important that the latest version of Solidity, i.e. Solidity 0.4.16 should be used for the code.

By looking at the basic elements of the smart contract that we are working on, we can easily see that the contracts are simply collections of code and data that effectively correspond to some specific contract address based on the blockchain.

Building the contract

When you are looking to work on the contract, you must work on the counter state variable. In order to do this, you will need to assign a particular integer such as that of 256 bits. The 256 bits can work for the design of Ethereum Virtual Machine. You will then need to create two functions for the variable assignment which can function as the modifier.    

Avatar

By Ashok Rathod

Life is all about solving problems. Ashok is a software developer, technology enthusiast, founder, and director of a reputed software development company. Eager to help brilliant minds, and entrepreneurs with MVP ( Minimum Viable Product ) development, and technology consultation. Ashok is an engineer, a strategist, an investor, an architect, and a blogger who love to share about technology.

Recent Posts

×
×