<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Izuchukwu Onukwube</title>
    <description>The latest articles on Forem by Izuchukwu Onukwube (@codewitheric).</description>
    <link>https://forem.com/codewitheric</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F726283%2F8ce02148-16f2-497a-ac9a-84509e8cc788.jpeg</url>
      <title>Forem: Izuchukwu Onukwube</title>
      <link>https://forem.com/codewitheric</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/codewitheric"/>
    <language>en</language>
    <item>
      <title>How to create a private blockchain network using Go-Ethereum(geth).</title>
      <dc:creator>Izuchukwu Onukwube</dc:creator>
      <pubDate>Tue, 21 Jun 2022 13:41:33 +0000</pubDate>
      <link>https://forem.com/codewitheric/how-to-create-a-private-blockchain-network-using-go-ethereumgeth-4inn</link>
      <guid>https://forem.com/codewitheric/how-to-create-a-private-blockchain-network-using-go-ethereumgeth-4inn</guid>
      <description>&lt;p&gt;In this tutorial you will learn how to connect to the Ethereum Mainnet and then later build a private blockchain network using Go-Ethereum(geth). We are going to be working with the &lt;strong&gt;Genesis.json&lt;/strong&gt; file, so if you read my previous post then you're good to go. If not you can check it out &lt;a href="https://dev.to/codewitheric/the-genesisjson-file-a-quick-intro-28pd"&gt;Here&lt;/a&gt;, and then come back.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;strong&gt;Genesis.json&lt;/strong&gt; file we will be using for this tutorial can be found &lt;a href="https://drive.google.com/file/d/1sFuiUhgYWBgJMkAPGPRBpHFgAeFSk1df/view?usp=sharing" rel="noopener noreferrer"&gt;Here&lt;/a&gt;. With that said let's get started.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is Go-Ethereum (geth)
&lt;/h2&gt;

&lt;p&gt;Go-Ethereum (geth) is a blockchain node, it is downloaded into your computer and runs locally. It is a command line tool and  will give you access to the blockchain via a javascript JSON RPC (this is the connection between you and the blockchain). When you run Geth, it tries to find other blockchain nodes, connects to them and start downloading blocks so it basically replicates the blockchain locally on your computer. Geth then opens a javascript JSON RPC on your computer to allow you interact with the node.&lt;/p&gt;

&lt;p&gt;There are several ways in which Geth synchronizes. It's either as a &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Full Sync (Slow)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It downloads block headers.&lt;/li&gt;
&lt;li&gt;It downloads block bodies of every block.&lt;/li&gt;
&lt;li&gt;It downloads All historical transactions.&lt;/li&gt;
&lt;li&gt;It takes 30GB of Data.&lt;/li&gt;
&lt;li&gt;It takes time to process and finish.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Fast Sync (Default)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It downloads block headers.&lt;/li&gt;
&lt;li&gt;It downloads block bodies of every block.&lt;/li&gt;
&lt;li&gt;It downloads the last 1024 transactions.&lt;/li&gt;
&lt;li&gt;It takes a few hours.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Light Sync (Experimental)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It downloads only block headers.&lt;/li&gt;
&lt;li&gt;Takes the latest snapshot of the current state.&lt;/li&gt;
&lt;li&gt;It is less secure but much faster.&lt;/li&gt;
&lt;li&gt;It doesn't take up much space.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Downloading &amp;amp; Installing Geth
&lt;/h2&gt;

&lt;p&gt;To install Geth you have to go &lt;a href="https://geth.ethereum.org/downloads/" rel="noopener noreferrer"&gt;Here&lt;/a&gt;, once you get there it will then try to retrieve the current version number of Geth and give you different options for Linux, Windows, Mac and also the sources.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note that Geth does not have any upgrade mechanism implemented, so you will have to check from time to time for new releases.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I'm on windows and as of this writing i will download the version below. Please make sure to download the latest version that is compatible with your computer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Geth 1.10.18 64bit installer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Starting Geth
&lt;/h2&gt;

&lt;p&gt;Now that we have downloaded and installed Geth, remember that Geth is a command line tool so to run it we need to navigate to our command line interface, for me i will be using powershell. Once you have your CLI opened we want to start Geth without any parameters. To do this type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;geth
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;once you have done that, Geth would start downloading the ethereum mainnet on your computer. It would start something called &lt;strong&gt;Block synchronization&lt;/strong&gt; and then it imports all the blocks from the network into your computer. Remember i said that there are 3 different ways in which Geth synchronizes, so when you start Geth for the first time it synchronizes using the &lt;strong&gt;Fast Sync&lt;/strong&gt;. But if I interrupt it right now and restart Geth, it would start synchronizing using the &lt;strong&gt;Full Sync&lt;/strong&gt; (you will notice it's much slower).&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx3qirysks3g3zditdndu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx3qirysks3g3zditdndu.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note that the blocks that are been downloaded into your computer are normal files and I will show you where you can find this files (blocks).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Assuming I interrupted Geth (by typing &lt;code&gt;Ctrl + C&lt;/code&gt; on powershell) while it was synchronizing, and it switched to a &lt;strong&gt;Full Sync&lt;/strong&gt; on restart, how do I switch back to a &lt;strong&gt;Fast Sync&lt;/strong&gt;? well to do this you would have to locate where the files are stored and delete the &lt;strong&gt;geth&lt;/strong&gt; folder. Here is where you can locate the files on your computer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mac: &lt;code&gt;~/Library/Ethereum&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Linux: &lt;code&gt;~/.ethereum&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Windows: &lt;code&gt;~/AppData/Local/Ethereum&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F89dpmhcopvhpdlxbr6mb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F89dpmhcopvhpdlxbr6mb.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;strong&gt;keystore&lt;/strong&gt; folder is where Geth stores your private keys when you create a new account, so don't delete it and always back it up properly.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Log-Outputs From Geth Explained
&lt;/h2&gt;

&lt;p&gt;Here I would like to explain some of the log-ouputs we get when we run Geth. I have highlighted them in the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ourzrro8xi54jhoqhep.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ourzrro8xi54jhoqhep.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Notice here that the &lt;strong&gt;chainID&lt;/strong&gt; is set to 1, this number is reserved for the Ethereum &lt;strong&gt;Mainnet&lt;/strong&gt; only, while 2 &amp;amp; 3 are reserved for the &lt;strong&gt;Testnets&lt;/strong&gt;. Therefore you can not use any of these numbers when creating a private blockchain network.&lt;/li&gt;
&lt;li&gt;The log-output also displays the &lt;strong&gt;Geth instance&lt;/strong&gt; which your 
computer is running on. Be sure to download the latest version of Geth or else you might not be able to connect to the Ethereum Mainnet. As of this writing i'm running on &lt;strong&gt;Geth version 1.10.18&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Notice the &lt;strong&gt;IPC endpoint&lt;/strong&gt;, IPC stands for &lt;strong&gt;Interprocess communication&lt;/strong&gt;. This endpoint is used when you want to connect to 
a running Geth node.&lt;/li&gt;
&lt;li&gt;Note that there is no &lt;strong&gt;RPC endpoint&lt;/strong&gt; opened yet, because when 
you start Geth without any parameter then it will not open any 
HTTP RPC endpoint. That means if you try interacting with this running node it will not work.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Connecting &amp;amp; Interacting With A Running Geth Instance.
&lt;/h2&gt;

&lt;p&gt;Now that we have a Geth instance running, we then want to connect to it. To do this we are going to use the &lt;strong&gt;IPC endpoint&lt;/strong&gt; from Geth. We are going to run Geth on one powershell and try connecting to it from another one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1z1ik0j2w4x1oqyervu7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1z1ik0j2w4x1oqyervu7.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
From the image above, we are running Geth on the left and we connect to it on the right using the IPC endpoint from the running&lt;br&gt;
Geth instance. To connect to Geth you have to type this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;geth attach ipc:\\.\pipe\geth.ipc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The above command brings Geth into a client mode. And now we can interact with it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now that we have connected to our running Geth instance, we can see the &lt;strong&gt;instance&lt;/strong&gt; that we are connected to and the different &lt;br&gt;
&lt;strong&gt;modules&lt;/strong&gt; we have. For example we have an &lt;strong&gt;admin&lt;/strong&gt; module with different functions that we can call, I highlighted them below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3a8ntmpl3649n0vp3hxu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3a8ntmpl3649n0vp3hxu.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can also create a new account using this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;personal.newAccount();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;This would require a passphrase, although you won't see it as you type. Once you've have done that you should have a new account (address). The private keys for this account is stored in the &lt;strong&gt;keystore&lt;/strong&gt; directory&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flhrjaeghzgwcxhx7gb0h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flhrjaeghzgwcxhx7gb0h.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is basically how to connect to a running blockchain node and interact with it using JavaScript commands in your command line. There is a lot more commands that you can run, and &lt;a href="https://geth.ethereum.org/docs/rpc/server" rel="noopener noreferrer"&gt;here&lt;/a&gt; is where you can find them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Creating A Private Blockchain Network.
&lt;/h2&gt;

&lt;p&gt;Now that we have a basic understanding on how to run, connect and interact with a blockchain node, I would like to show you how you can actually create a private network with Geth. We are going to be working with the &lt;strong&gt;Genesis.json&lt;/strong&gt; file so be sure to download it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next we create a folder containing the genesis.json file and open it on powershell or you preferred terminal. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvx6ikehw6kwdgadu4mhj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvx6ikehw6kwdgadu4mhj.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In our terminal, we then initialize a new directory with the genesis.json file where our blocks are going to be stored.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;geth init .\genesis.json --datadir mychaindata
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Now Geth would initialize a new &lt;strong&gt;genesis block&lt;/strong&gt; inside the directory that we specified i.e &lt;strong&gt;mychaindata&lt;/strong&gt;. You should see a log that says &lt;em&gt;Successfully wrote genesis state&lt;/em&gt; .&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now let's start our new private blockchain with the &lt;strong&gt;mychaindata&lt;/strong&gt; directory. To do this type:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;geth --datadir .\mychaindata\
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F59j3wlfwnrhau5u7okn0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F59j3wlfwnrhau5u7okn0.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Notice the &lt;strong&gt;chainID&lt;/strong&gt; is set to 15, which is what we have in the genesis.json file. You can also see that Geth opens the &lt;strong&gt;IPC endpoint&lt;/strong&gt;, also notice that Geth doesn't start the block synchronization because we are on our private network.  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Sometimes Geth starts synchronizing with another network with the same &lt;strong&gt;chainID&lt;/strong&gt;, this happens because it's in &lt;strong&gt;discovery mode&lt;/strong&gt;. If it finds other nodes with the same chainID then it will start downloading those blocks that are already in that chain and connect to it. When running a private network this is something we want to avoid. Therefore to avoid this you need to run this:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;geth --datadir .\mychaindata\ --nodiscover 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Connecting &amp;amp; Interacting With Our Private Network.
&lt;/h2&gt;

&lt;p&gt;Now that we have a private network running, when want to connect to it from another terminal. To do this we are going to use the &lt;strong&gt;IPC endpoint&lt;/strong&gt; from our running private network. This is very similar to the way we connect to a running Geth instance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpl40159tfpcf35euft5k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpl40159tfpcf35euft5k.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
From the image above, we have our private network running on the left and we have connected to it on the right using this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;geth attach ipc:\\.\pipe\geth.ipc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have connected to our private network, lets write some JavaScript commands to interact with it. First we want to check if we have any accounts on our private network, to do this type this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eth.accounts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Notice that we get back an empty array &lt;code&gt;[]&lt;/code&gt;, that means we don't  have any account on our private network.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Since we don't have an account, let's create one. To do this type this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;personal.newAccount();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;I'm sure you're already familiar with this command. You will be asked to provide a passphrase just like we did previously. Once that's done you should have an account created. Also the private keys for this account would be stored in the &lt;strong&gt;Keystore&lt;/strong&gt; directory.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Adding Ether To Our Account&lt;/strong&gt; &lt;br&gt;
Now that we have an account on our private network, we want to add some Ether into that account. To do this we are going to &lt;strong&gt;Mine&lt;/strong&gt; Ether on our private network into that account. For mining you need to have a coinbase account set, so when the miner is running it will credit your Ether to into the coinbase account. To do this run this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eth.coinbase
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Notice that the coinbase account is the same as the account we created earlier, this is because it chooses the first account in the &lt;code&gt;eth.accounts&lt;/code&gt; array&lt;code&gt;[]&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4t26jmzy77g7t2id4gzp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4t26jmzy77g7t2id4gzp.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's start the miner, to do this type this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;miner.start(1);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;When you start a miner you have to pass in one parameter, and this is the amount of threads it will run on. So we pass in 1.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once the miner starts it will return &lt;code&gt;null&lt;/code&gt;, this is perfectly fine. But on the main window where the private network is running, you would see some logs like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fovxx3vu1xh1jwjmlecph.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fovxx3vu1xh1jwjmlecph.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Notice that the mining thread is set to 1, it then starts mining and committing new blocks. Every time a block is successfully sealed, Ether would be credited into your account. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now let's have a look at the balance of our account. To do this we a going to use the &lt;code&gt;web3&lt;/code&gt; endpoint.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;web.eth.getBalance(eth.accounts[0]); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OR&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eth.getBalance(eth.accounts[0]); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuygci6arerytqtscufeb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuygci6arerytqtscufeb.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;As long as the miner is running and a new block is successfully sealed, Ether will always be credited into the account and the amount of Ether in the account increases. Mining will slow down after some time, this is because when a new block is mined the difficulty increases(I talked about this in my previous post).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now we want to convert the money in our account from &lt;strong&gt;Wei&lt;/strong&gt; to &lt;strong&gt;Ether&lt;/strong&gt;. To do this type this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;web3.fromWei(eth.getBalance(eth.accounts[0]), "ether");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With that said, this is how you interact and mine Ether with your private blockchain network.&lt;/p&gt;

&lt;p&gt;That's it for this post guy's, I hope you enjoyed it as much as i did. If you have any questions or run into any issue while following this post, be sure to drop a comment and I will reply.&lt;/p&gt;

&lt;p&gt;Keep building, catch you later!&lt;/p&gt;

</description>
      <category>web3</category>
      <category>ethereum</category>
      <category>dapps</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>The Genesis.Json file - A quick intro</title>
      <dc:creator>Izuchukwu Onukwube</dc:creator>
      <pubDate>Mon, 13 Jun 2022 22:04:40 +0000</pubDate>
      <link>https://forem.com/codewitheric/the-genesisjson-file-a-quick-intro-28pd</link>
      <guid>https://forem.com/codewitheric/the-genesisjson-file-a-quick-intro-28pd</guid>
      <description>&lt;p&gt;Hey it's been a while...&lt;/p&gt;

&lt;p&gt;I have been doing a lot of learning in the blockchain space and I recently learnt about the &lt;strong&gt;genesis.json&lt;/strong&gt; file, so i'm back here to share my learnings with you guys. If you are someone who is curious about the web3 space, i hope you find this post useful.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Genesis.json file
&lt;/h2&gt;

&lt;p&gt;The Genesis.json file is a config file for Go-Ethereum (a blockchain node), that is needed in order to create a private blockchain network. It is the file that Go-Ethereum needs to create the very first block (Genesis block) of your private network.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some content of the file
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;u&gt;ChainId&lt;/u&gt;: This can be set to any number except 1, 2 and 3, because 1 is reserved for the &lt;strong&gt;Mainnet&lt;/strong&gt; while 2 &amp;amp; 3 is reserved for the &lt;strong&gt;Testnets&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;u&gt;Homesteadblock&lt;/u&gt;: Ethereum is separated into certain releases, the previous one was &lt;strong&gt;Frontier network&lt;/strong&gt; launched on July 30th, 2015 and next release was called the &lt;strong&gt;Homestead&lt;/strong&gt; launched on Mar-14-2016. It is usaually set to zero (0) in the Genesis.json file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;u&gt;eip155Block&lt;/u&gt;: eip stands for Ethereum improvement protocol. It is usually set to zero (0) in the Genesis.json file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;u&gt;Difficulty&lt;/u&gt;: This is very important if you want to mine ether on your network or create contracts. The lower it is, the faster mining will be, the easier it will be for your miner to solve the mathematical riddle in order to mine blocks. If you realize that mining takes too long, you can initialize &lt;br&gt;
a new private network and set the difficulty lower. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;u&gt;GasLimit&lt;/u&gt;: This is necessary for deploying contracts, each contract written in solidity will be compiled to something like assembly or byte code. And each of them takes up some gas. The GasLimit is here to limit the amount of logic that you can run on a miner. The higher the GasLimit, the more complex your contracts can get. The current GasLimit on the Ethereum network is around 6 million or even more.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;u&gt;Alloc&lt;/u&gt;: This is set to pre-allocate ether to certain accounts. &lt;br&gt;
When you initialize your private network you might want to allocate ether to some accounts and this is where you set those accounts before initializing your private network. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's it for this post guy's, I hope I've been able to at least give you an idea about what the Genesis.json file is and why this space is so interesting.&lt;/p&gt;

&lt;p&gt;Keep building, catch you later!&lt;/p&gt;

</description>
      <category>web3</category>
      <category>blockchain</category>
      <category>tutorial</category>
      <category>ethereum</category>
    </item>
    <item>
      <title>Defining the Blockchain using Bitcoin as an example.</title>
      <dc:creator>Izuchukwu Onukwube</dc:creator>
      <pubDate>Wed, 30 Mar 2022 16:27:25 +0000</pubDate>
      <link>https://forem.com/codewitheric/defining-the-blockchain-using-bitcoin-as-an-example-1l42</link>
      <guid>https://forem.com/codewitheric/defining-the-blockchain-using-bitcoin-as-an-example-1l42</guid>
      <description>&lt;p&gt;So you have been hearing a lot of noise about this blockchain thingy but haven't been able to understand or wrap your head around it, well you're not alone. I started hearing about the blockchain around August 2020 (I know pretty late right? ) and the curiosity in me did not let me rest until I got at least a basic understanding about this new technology.&lt;/p&gt;

&lt;p&gt;In this post I would love to explain what the blockchain means using bitcoin as an example. I'm sure many of us have heard the term "Bitcoin", and some of us might even have loads of it haha...so I hope you would be able to relate.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Enough talk, let's dive in!&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Using Bitcion as an example, the blockchain is a public ledger of all bitcoin transactions that have ever taken place right back to the very first transaction. Hence the blockchain is an ever evolving piece of technology.&lt;/p&gt;

&lt;p&gt;It's constantly growing as new blocks are added. The transaction which are being added unto the blockchain are being processed by computers (Nodes) connected to the network. These Nodes are located around the globe, hence being a decentralized technology. Also as each block is been added unto the chain, it's done so in a chronological order and anything that happens on the network happens as a whole.&lt;/p&gt;

&lt;h2&gt;
  
  
  Features of the Blockchain:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Decentralized&lt;/strong&gt;: The blockchain network is decentralized, meaning it doesn’t have any governing authority or a single person looking after the network. Rather a group of nodes maintains the network making it decentralized.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Immutable&lt;/strong&gt;: This means that if you put something on the blockchain, it is really hard to change, it's pretty much there forever.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Distributed&lt;/strong&gt;: This means that no one computer(Node) can decide. It's a network of computer(Nodes) around the world sharing that decision.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Public Ledger&lt;/strong&gt;: It's just a table, like an excel table that contains a lot of information opened to everyone.&lt;/p&gt;

&lt;p&gt;There are many other features and use cases of the blockchain. But I hope I've been able to at least give you an idea about what the blockchain is and why it's so interesting.&lt;/p&gt;

&lt;p&gt;Keep building, catch you later!&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>crypto</category>
      <category>tutorial</category>
      <category>web3</category>
    </item>
  </channel>
</rss>
