How to Build a Private Ethereum Blockchain – ConsenSys Media

How to Build a Private Ethereum Blockchain

The following instructions walk through the installation of a single knot private installation of an Ethereum blockchain using the Go-Ethereum client.

Basic practice working on Linux directive line

Step Two: Install golang-go package

Step Trio: Build go-ethereum from github

Step Four: Test geth installation

Expect a response similar to:

Step Five: Create an account to use as the coinbase for your blockchain knot

You will be prompted to set a password for the account, DON’T Leave behind YOUR PASSWORD, you will not be able to recover it later and won’t be able to spend the ether you mine or unlock that account. After injecting the password twice, you should expect to get a response back like this:

This is the public key of the Ethereum account. Ethereum convention is to prefix accounts with 0x so the account is sometimes seen as 0x941f1fobo8757457be0b52d83a1e3e566473ed61.

Step 7: Initialize the blockchain from your CustomGenesis.json file

You should expect to see output similar to this:

Congratulations! You have initialized a private Ethereum blockchain!!

Before we stir on, let’s take a break for some optional exploration of the files we have generated. In your home directory you will now see a hidden directory called .ethereum .

You’ll notice the public key is there in plaintext “address”:”941f1f0b08757457be0b52d83a1e3e566473ed61" , the private key is encrypted in the file using the password you provided when creating the account.

Commence geth with the following directive line arguments

You need to instruct your knot to mine so that blocks are being created and so that when you begin to send transactions to the chain they will be processed and included in blocks. The nodiscover and maxpeers arguments are simply for security so that your chain implementation doesn’t attempt to detect any peers nor accept any peer requests. We set the value of the networkid argument to a random integer that isn’t 1, Two, three or four as those are reserved as identifiers for the public Ethereum networks. Ultimately, we enable rpc so your chain responds to the remote JSON-RPC API calls as is documented here: https://github.com/ethereum/wiki/wiki/JSON-RPC.

You will also notice that mining starts and your knot will begin generating blocks:

That’s it! Your blockchain is now running, processing blocks and listening to remote RPC calls so that you and your code can interact with it. In fact let’s attempt a few tests using the JSON-RPC API documented here: https://github.com/ethereum/wiki/wiki/JSON-RPC. All of the methods documented here can be executed against your running blockchain. Leave your chain running and open a 2nd window with a shell to your VM.

You should receive a response like this:

Now check the balance in ether of the Ethereum account that your blockchain is mining to:

You should receive a response like this:

The result is returned in hexadecimal, which when converted to decimal is: 1,16e21 . As noted in the documentation for the eth_getBalance method, the value returned is in wei, which is the smallest denomination of ether. Using a converter like this one, you can convert that value in wei to ether to see you have one thousand one hundred sixty ether in your account. If only it were real ether! This ether only has value on this private network.

Now you have your single knot private blockchain. To add a 2nd knot, go after the steps above to build your 2nd knot.

Next, since we are still using the –nodiscover option, we need to explicitly instruct each knot to peer with the other at startup.

After kicking off each example, you will be able to check that they are peering using the JSON-RPC method call.

That’s it, from here you can proceed to play with your fresh chain and experiment with the JSON-RPC API and other begin flags.

How to Build a Private Ethereum Blockchain – ConsenSys Media

How to Build a Private Ethereum Blockchain

The following instructions walk through the installation of a single knot private installation of an Ethereum blockchain using the Go-Ethereum client.

Basic practice working on Linux instruction line

Step Two: Install golang-go package

Step Three: Build go-ethereum from github

Step Four: Test geth installation

Expect a response similar to:

Step Five: Create an account to use as the coinbase for your blockchain knot

You will be prompted to set a password for the account, DON’T Leave behind YOUR PASSWORD, you will not be able to recover it later and won’t be able to spend the ether you mine or unlock that account. After injecting the password twice, you should expect to get a response back like this:

This is the public key of the Ethereum account. Ethereum convention is to prefix accounts with 0x so the account is sometimes seen as 0x941f1fobo8757457be0b52d83a1e3e566473ed61.

Step 7: Initialize the blockchain from your CustomGenesis.json file

You should expect to see output similar to this:

Congratulations! You have initialized a private Ethereum blockchain!!

Before we stir on, let’s take a break for some optional exploration of the files we have generated. In your home directory you will now see a hidden directory called .ethereum .

You’ll notice the public key is there in plaintext “address”:”941f1f0b08757457be0b52d83a1e3e566473ed61" , the private key is encrypted in the file using the password you provided when creating the account.

Commence geth with the following guideline line arguments

You need to instruct your knot to mine so that blocks are being created and so that when you begin to send transactions to the chain they will be processed and included in blocks. The nodiscover and maxpeers arguments are simply for security so that your chain implementation doesn’t attempt to detect any peers nor accept any peer requests. We set the value of the networkid argument to a random integer that isn’t 1, Two, three or four as those are reserved as identifiers for the public Ethereum networks. Eventually, we enable rpc so your chain responds to the remote JSON-RPC API calls as is documented here: https://github.com/ethereum/wiki/wiki/JSON-RPC.

You will also notice that mining starts and your knot will begin generating blocks:

That’s it! Your blockchain is now running, processing blocks and listening to remote RPC calls so that you and your code can interact with it. In fact let’s attempt a few tests using the JSON-RPC API documented here: https://github.com/ethereum/wiki/wiki/JSON-RPC. All of the methods documented here can be executed against your running blockchain. Leave your chain running and open a 2nd window with a shell to your VM.

You should receive a response like this:

Now check the balance in ether of the Ethereum account that your blockchain is mining to:

You should receive a response like this:

The result is returned in hexadecimal, which when converted to decimal is: 1,16e21 . As noted in the documentation for the eth_getBalance method, the value returned is in wei, which is the smallest denomination of ether. Using a converter like this one, you can convert that value in wei to ether to see you have one thousand one hundred sixty ether in your account. If only it were real ether! This ether only has value on this private network.

Now you have your single knot private blockchain. To add a 2nd knot, go after the steps above to build your 2nd knot.

Next, since we are still using the –nodiscover option, we need to explicitly instruct each knot to peer with the other at startup.

After embarking each example, you will be able to check that they are peering using the JSON-RPC method call.

That’s it, from here you can proceed to play with your fresh chain and experiment with the JSON-RPC API and other begin flags.

Related video:

Leave a Reply