Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Introduction
A blockchain is a digital ledger of records that’s arranged in chunks of data called blocks. These blocks
then link with one another through a cryptographic validation known as a hashing function. Linked
together, these blocks form an unbroken chain — a blockchain.
The reason that this type of data structure is useful for things like cryptocurrencies is decentralization,
meaning the records inside this chain aren’t stored in any single location, are accessible by everyone, and
are immutable by any one party.
Applications
Although blockchain is most commonly associated with Bitcoin, there are many uses for this technology.
There are several broad categories of blockchain applications, a couple of which include:
Hands-on
From time to time I plan to emulate an Ethereum environment. The idea behind is to observe how
Ethereum nodes work to each other, and how different accounts interact in transaction and contract
deployment. For testing, most contract deployment example nowadays is mainly on testrpc or
testnet, but how the contract works among nodes is still new to m
1
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
Fig. 1
Background
Ethereum blockchain network is simply lots of EVM (Ethereum Virtual Machines) or “nodes” connected to
every other node to create a mesh. Each node runs a copy of the entire blockchain and competes to mine
the next block or validate a transaction. Whenever a new block is added, the blockchain updates and is
propagated to the entire network, such that each node is in sync. Ethereum’s Go implementation is
called Geth
Fig. 2
To become a node in the Ethereum network, your computer will have to download and update a copy of
the entire Ethereum blockchain. To achieve this Ethereum provides tools that you can download, connect
to the Ethereum network with and then interact with it. These are:
2
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
Geth — "……if you have experience with web development and are interested in
building frontends for dapps, you should experiment with Geth. "
Eth — "…If you want added security by running two different implementations
in parallel or are serious about GPU mining, then the C++ "Eth" client is
for you. "
Pyethapp — " …If you are a Python developer that wants to build
decentralized apps or are interested in Ethereum for research or an
academic purpose, this is a great client"
Each of these tools will eventually provide us access to a console — a JavaScript environment that
contains all of the main features that we’d need later so I am guessing no matter what tool you choose to
set up your blockchain, we should eventually converge on the console.
We decide to go with Geth or this labs, since our team have some understanding of web development.
The rest of this post assumes that we are using Geth to interact with the Ethereum Network.
Geth is a command line interface (CLI) tool that communicates with the Ethereum Network and acts as
the a link between your computer, its hardware and the rest of the Ethereum nodes or network computers.
If a block is mined by another node, your Geth program will pick it up and then pass on the new
information onto your GPU or CPU to update the blockchain. With Geth, you can
• mine ether (ether is the cryptocurrency fueling the Ethereum network)
• transfer funds between addresses
• create smart contracts and send transactions to them
• explore block history and much much more
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
Once you have installed Geth, you can technically connect to the Main or public Ethereum blockchain
Network and run a full ethereum node. But we don’t want to do that just yet because If you are reading
this article, chances are you have no ether (Ethereum’s cryptocurrency) − and without ether you cannot
really do much on the Main blockchain.
Blockchain
As you probably know by now, a blockchain is nothing but a digital ledger in which transactions are
recorded chronologically and publicly. These transactions are recorded in blocks, and nodes in a
distributed network compete to find the next valid block. Once a valid block is found, it is added to the
blockchain, and this information relayed to the network. Every node then updates their blockchain to the
latest copy.
Note: every blockchain starts with a Genesis Block, the very first block in
the chain; block ZERO— the only block that does not have a predecessor.
4
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
To create our private blockchain then, we will create a genesis block. To do this, we will create a custom
Genesis file, and ask Geth to use that genesis file to create our own genesis block , which in turn will be
the start of our custom private blockchain.
{
"config": {
"chainId": 987,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"difficulty": "0x400",
"gasLimit": "0x8000000", //set this really high for testing
"alloc": {}
}
}
• config: the config block defines the settings for our custom chain and has certain attributes to
create a private blockchain
• chainId: identifies our blockchain, the main Ethereum chain has its own ID, but we will set it to a
unique value for our private chain.
• homesteadBlock: Homestead is the second major version of the Ethereum platform and is the
first production release of Ethereum. It includes several protocol changes. Since we are already
on homestead version, this attribute is 0.
• difficulty: This value is used to control the Block generation time of a Blockchain. The higher
the difficulty, the statistically more calculations a Miner must perform to discover a valid block.On
our test network, we will keep this value low to avoid waiting during tests, since the generation of
a valid Block is required to execute a transaction on the Blockchain.
• gasLimit: this value specifies current chain-wide limit of 'Gas' expenditure per block. Gas is
Ethereum's fuel that is spent during transactions. We will mark this value high enough in our case
to avoid being limited during tests.
• alloc: This is where you can create your wallet and pre fill it with fake ether. For this post
however, we will mine our ether locally quickly so we don’t use this option.
5
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
At this point, lets go ahead and create our "myGenesis.json" file. I simply used a text editor and
stored it in a folder on my computer.
Next open terminal and assuming you have installed Geth, simply run this snippet
This snippet instructs Geth to use the "myGenesis.json" file you created as to be the first block of your
custom blockchain. Then, we also specify a data directory where our private chain data will be stored.
Geth will create the data directory for you. Just choose a location that is separate from the public
Ethereum chain folder, if you have one
Congratulations!
You just built your first private ethereum blockchain and mined some ether! Lots of details, but I am
hoping some of this made sense, and gave you a little more clarity on how blockchains work.
In the next post, we will add another node to our private blockchain, write and deploy smart contracts and
demonstrate how to call contract.
Note: It is important that what we mean by “private Ethereum blockchain” in this context has
absolutely nothing to do with the “private blockchain” championed by Hyperledger, Eris/Monax, or the
recently announced Enterprise Ethereum Alliance. These are different codebases with different client
applications, so they correspond to different implementations of a different set of concepts. They are
private in the sense that they limit who has access to their chain. They are also called permissioned
blockchains, and to be perfectly transparent, we wish they were not even called blockchains at all. In
this series of articles, what we call “private blockchain” is a private instance of the Ethereum
implementation. Same code base, same client application, different network identifier and genesis
block. In other words, what we will come to create in this series is a chain with the same rules as the
main chain, the same consensus algorithm too, but a different root block. This will become clearer in
part 3. For more information about the 3-layer model and differences between concepts,
implementations and instances, you can also watch our Devoxx talk and read this article.
Our private chain needs miners in order to validate and propagate blocks of transactions within the
blockchain. Miners will also be used to generate ether to pay for the gas required to process transactions
on the Ethereum blockchain. Note that this ether will only be usable within our private blockchain.
Unfortunately, the Raspberry pi is not powerful enough to be used as a miner. The mining process is just
too intense. This is why we will deploy at least two miners on our computer.
6
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
Requirements
Before we describe the steps to start the miners, it is important to understand the requirements for each
node to join the same private blockchain:
• Each node will use a distinct data directory to store the database and the wallet.
• Each node must initialize a blockchain based on the same genesis file.
• Each node must join the same network id different from the one reserved by Ethereum (0 to 3 are
already reserved).
• The port numbers must be different if different nodes are installed on the same computer.
1. From your computer, create the folder that will host your first miner, assume we want to place the
folder on the Desktop, right-click anywhere on the Desktop, and add name the new folder
PrviaceChain3.
Fig. 4a
Fig. 4b
7
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
2. Next right-click on the PrivateChain3 folder and open it with Git Bash Here cmd, as shown in Fig.
5
Fig. 5a
Fig. 5b
Note: our genesis block is called "genesis.json" and is stored under PrivateChain3 folder.
3. Create a text file under PrivateChain3, called "genesis.json", with the following content:
{
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0
},
"alloc": { },
"coinbase" : "0x0000000000000000000000000000000000000001",
"difficulty" : "0x440",
"extraData" : "",
"gasLimit" : "0x2fefd8",
8
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
"nonce" : "0x0000000000000042",
"mixhash" :
"0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" :
"0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00"
}
4. To do this, type the following command to create the blockchain for the first miner:
Fig. 6
9
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
...
I1226 00:44:16.604262 cmd/geth/chaincmd.go:131] successfully wrote genesis
block and/or chain rule set:
6e92f8b23bcdfdf34dc813cfaf1d84b71beac80530506b5d63a2df10fe23a660
Note:
The logs provide the following information:
• you need a default account
• the blockchain has been successfully created
If you list the content of the chaindata folder, you will notice the following subfolders:
• geth: contains the database of your private blockchain (chaindata).
• keystore: location of your wallet used to store the accounts that you will create on this node.
Fig. 7
7. Now, to create the default account, type the following command. Keep the password in a safe place:
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
Fig. 8
Add an additional account for testing purpose:
Address: {7712ef60c37f2daca3b7a6c18baeab9e44d91c8f}
Address: {f3750459561e7d928a55c1e688ac4788de4343f1}
11
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
Fig. 11
Fig. 9
12
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
> eth.coinbase
"0xe803ad99fbce665c0d71074406be1822460e58f4"
>
> eth.accounts
["0xe803ad99fbce665c0d71074406be1822460e58f4",
"0x7712ef60c37f2daca3b7a6c18baeab9e44d91c8f",
"0xf3750459561e7d928a55c1e688ac4788de4343f1",
"0xfbbfff4bdcad3b6104e33098cf2ef30479b0aa04"]
>
Fig. 10
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
> eth.getBalance(eth.coinbase)
> eth.getBalance("0xe803ad99fbce665c0d71074406be1822460e58f4")
eth.getBalance("0xf3750459561e7d928a55c1e688ac4788de4343f1")
Fig. 11
14
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
Fig. 12
Fig. 12b
15
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
Fig. 12c
As the mining continues, let’s open a new geth console and attach it the mining one – Not working yet
Note
• You will notice that the server and the mining process start.
• You default account will receive ethers mined by the node.
• If you start Mist, you will see that the default account is rewarded by ethers.
• Remember that these ethers are fake money only available in your private blockchain and not on
the live main chain.
Stop Mining
Stop Mining and let check balance and also send ether
> eth.getBalance(eth.coinbase)
2.364e+21
>
Or
16
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
> eth.getBalance("0xe803ad99fbce665c0d71074406be1822460e58f4")
2.364e+21
>
Note: the default account has plenty of ethers obtained during the mining process. We will use
them to test our solutions.
2. You may also use the following command to get the balance in ether:
> web3.fromWei(eth.getBalance(eth.coinbase))
2364
Fig. 13
Note: by default, the balance is expressed in Wei that is the base unit of ether.
Set Password
3. From the geth console issue the following command
> personal.newAccount()
Fig. 14
> personal.newAccount()
> personal.unlockAccount("0xe803ad99fbce665c0d71074406be1822460e58f4","password")
That is:
> personal.unlockAccount("0xe803ad99fbce665c0d71074406be1822460e58f4","password")
true
17
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
>
Sending ethers
Please ensure that the account is unlocked before performing the next steps, otherwise you’ll get error as
shown below.
Fig. 15
5. From the Geth console, we send 10 ethers from account #0 to account #1:
Fig. 16
> eth.pendingTransactions
18
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
Fig. 17
> miner.start()
true
or exit the exit and then restart the geth console, and then start mining
8. After the mining process has started, stop mining, restart the geth console and proceed with next
steps
> eth.pendingTransactions
[]
19
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
10
12. Congratulations your blockchain miner is properly installed and working beautifully.
Ethereum-Wallet-installer-0-9-3.exe
Mist-installer-0-9-3.exe
2. Now open the Ethereum Wallet, you should see Fig. 18.
20
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
www.globalopenversity.org
Global Open Versity Building & Deploying s Private Network on Windows Machine v1.0
Fig. 18
Congratulations!
You just built your first private ethereum blockchain and mined some ether! Lots of details, but hope that
some of this made sense, and gave you a little more clarity on how blockchains work.
In the next post, we will add another node to our private blockchain, write and deploy smart contracts and
demonstrate how to call contract.
-----------------------------------------------
Kefa Rabah is the Founder of The Lake Institute. Kefa is knowledgeable in several fields of Science &
Technology, Information Security Compliance, Blockchain Technology, Distributed Ledger Technology
(DLT) and Project Management, and Renewable Energy Systems. He is also the founder of Global Open
Versity, a place to enhance your educating and career goals using the latest innovations and
technologies.
www.globalopenversity.org