Private etherium blockchain on a windows box

Facebook
Twitter
LinkedIn

Never miss a post!

Sign up for our newsletter and get FREE Development Trends delivered directly to your inbox.

You can unsubscribe any time. Terms & Conditions.
Categories

In this post i will cover the process of setting up an Etherium node on a windows box. The main piece of software required is Geth.

Geth is a command line tool written in Go that gives us the ability to run a full Etherium node implementation. We can perform the following tasks.

  • Mine ether.
  • Perform ether transactions from one address to another.
  • Deploy and mine smart contracts.
  • Monitor the full block history.

You can download Geth from the following repository This article was based on version v1.8.7. ( If future versions break this blog please drop me an email and I will update it).

The repository contains binaries wrapped in an msi or as zip file.

If you run Geth it will automatically connect to the Main or public Ethereum blockchain Network and run a full ethereum node. To perform transactions we would need real ether which is not a good idea for a test environment or if you want to implement your own managed Dapp.

Given that we will be running a private block chain we are not gonna connect our node with other peers on the internet but work as an isolated node.

First step we need to perform is to define the genesis block. The genesis block is the very first block in the chain. (i.e the block that has to predecessor.)

In Geth this is done by defining a custom Genesis file and configure Geth to use this genesis file to create the genesis block and our own private blockchain.

The genesis file is a json file that contains the following parameters. ( I only included the minimum parameters, additional configs setting can be set.  Full config information can be found from the following site.

[code]
{
"config":
{
"chainId" : 287,
"homesteadBlock" : 0,
"eip155Block" : 0,
"eip158Block" : 0,
},
"difficulty" : "0x400",
"gasLimit:"0x8000000",
"alloc" : {}
} [/code]

  • difficulty. Value used to control the Block generation time. On our private blockchain we will keep this value low to avoid waiting.
  • gasLimit. The “Gas” expenditure per Block. Gas represents the processing power spend the process transactions. In a private block chain you can set this value high so you have enough processing (fuel) to process transactions.
  • chainId. Unique identifier to our blockchain.
  • homesteadBlock/eip155Block/eip158Block define protocol versions. For our private blockchain values will be set to 0.

Now that we have created our genesis file we can instruct Geth to generate our genesis block.

geth -datadir “c:\Geth\Data” init “c:\Geth\Config\genesis.json”

 

Next step is to create our private network. The private network is started by running the following command.

 

geth –datadir c:\geth\Data\PrivateChain –networkid 4096

 

The networkid identifies our Ethereum network. You can use any random number

Now that we have the network up and running we need to create our account.

To perform the operation we need to launch a new command line and attach to the geth console.

Launch a new instance of the command prompt and run the following command.

geth attach ipc:\\.\pipe\geth.ipc

This will provide us with a Javascript environment were we can run commands.

Once the console is loaded, execute the following command to create a new account.

personal.newAccount()

We can now start mining by issuing miner.start(). Wait 30 seconds for mining to complete and check your balance to see how much ether we have in balance. Issue command

ether.getBalance(ACCOUNTNO). Where ACCOUNTNO is the hex value returned from the personal.newAccount() command.

and we are done.

We have create a private blockchain and mined our first block and generated ether. In the next blog post I will cover the process of adding additional nodes to our blockchain network.

Hope this tutorial was helpful. If you need assistance or consultancy  feel free to contact me on [email protected].

Facebook
Twitter
LinkedIn

Our website uses cookies that help it to function, allow us to analyze how you interact with it, and help us to improve its performance. By using our website you agree by our Terms and Conditions and Privacy Policy.