...by Daniel Szego
quote
"On a long enough timeline we will all become Satoshi Nakamoto.."
Daniel Szego
Showing posts with label Blockchain walkthrough. Show all posts
Showing posts with label Blockchain walkthrough. Show all posts

Friday, December 29, 2017

Azure Blockchain walkthrough - Setting up a Quorum Blockchain Demo

Azure Blockchain platform have some pretty cool solutions to create consortium blockchain solutions. In this walkthrough we are going to demonstrate one step by step guideline for setting up a Quorum demo environment including, configuring the environment and deploy the first applications on top. Quorum is an extension / fork of Ethereum for consortium scenarios, including two useful extensions:
- increased performance with a Proof of Authority algorithm
- private and confidential transactions
- node privacy

1. Choosing the necessary Azure Blockchain template: Azure Blockchain has many different templates. Two of them are important for Quorum consortium blockchains: with the help of "Quorum Single Member Blockchain Network" you can create a minimal infrastructure, with "Quorum Demo" a preconfigured demo environment is delivered.

Figure 1. Quorum Azure templates

2. Delivering Infrastructure: In this tutorial we deliver the "Quorum Demo" template. It requires the configuration of a standard Azure image with the usual virtual machine sizing parameters. All blockchain specific installation step will be configured in the post configuration.

Figure 2. Setting up Quorum demo infrastructure

3. Post configuration of the infrastructure: 

 ssh <user>@<ip> -- logging in into the environment
 git clone https://github.com/jpmorganchase/quorum-examples.git -- cloning the repo
 cd quorum-examples/examples/7nodes -- the 7 nodes demo
 sudo su -- changing to root
 ./raft-init.sh -- initialising the environment (you have to probably use sudo)
 ./raft-start.sh -- starting the environment (you have to probably use sudo)

If you see the following screen, the Quorum demo started successfully.


Figure 3. Quorum demo started successfully

Optionally, before starting the nodes it might be a good idea to pre-allocate some ether. The 7nodes demo uses the genesis.json genesis file. You can pre-allocate ether to the coinbase address with the following command:

"alloc": 
 {"0xed9d02e382b34818e88b88a309c7fe71e65f419d": {"balance":
    "111111111"}}

4. To test if things working you can attach to the nodes with the help of the Geth console and make further configuration if necessary (make sure that you are in the 7nodes demo folder, if you get permission denied error message use sudo at the beginning, if the ipc file is not found than there was probably an error in the previous step at setting up the network):

 geth attach ipc:qdata/dd1/geth.ipc

Optionally, after attachment it might be a good idea to distribute some of the preallocated ether, with the following command:

eth.sendTransaction({from:"0xed9d02e382b34818e88b88a309c7fe71e65f419d",to:"<to_address>", value: 100000000})

5. Testing a pre-deployed private contract: with the 7nodes demo scenario, there is a private contract, called simple storage that has already been deployed at the setting up of the network, you can test as starting two windows and attaching to the node 1 and node 4:

geth attach ipc:qdata/dd1/geth.ipc
geth attach ipc:qdata/dd4/geth.ipc

then configuring the contract

var address = "0x1932c48b2bf8102ba33b4a6b545c32236e342f34";


var abi = [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initVal","type":"uint256"}],"type":"constructor"}];

var private = eth.contract(abi).at(address)

then calling get function should deliver 42 on node 1 and 0 on node 4:

private.get()

6. Configure Truffle: Truffle must be configured to the environment with a custom network configuration that can be set in truffle.js. It is important to set the public address to the public address of the virtual machine and configure the 22000 (Quorum rpc port to be open):


Figure 4. Live (Quorum Azure) network configuration

You can use the following command for migration:

truffle migrate --network live --verbose-rp

If you configured correctly, you should be able to start a migration with Truffle. There might be some issues however, as an example, if you Truffle deployment will remain hanging in some scenarios. The reason for that is that the development javascript expects that the transaction was actually mined. As however in Quorum there is no mining, the process might stay hanging. One workaround is to use only one javascript deployment script and based on the transaction hashes check explicitly if the given transaction was correctly validated. Another workaround that sometimes work is to start the Truffle console explicit on a given node and execute the migration from there. And last but not least, do not forget to open the 22000 - 22008 ports on the Azure environment.  

7. Configuring metamask with Quorum: configuring metamask with quorum is pretty similar to configuring another given network via the Custom RPC of Metamask. Simply use the IP address and the port with http:


Figure 5. Metamask configuration for Quorum















Azure Blockchain walkthrough - Setting up Ethereum Consortium Blockchain

Azure Blockchain platform have some pretty cool solutions to create consortium blockchain solutions. In this walkthrough we are going to demonstrate one step by step guideline for creating, configuring a consortium network and develop and deploy the first applications on top. 

1. Choosing the necessary Azure Blockchain template: Azure Blockchain has many different templates. Two of them are important for Ethereum consortium blockchains: with the help of "Ethereum Consortium Blockchain" you can create a consortium infrastructure up to 12 nodes in one configuration step. With "Consortium Leader" or "Consortium Member", there is the possibility to do the same configuration step-by-step, with other words dynamically if a new member joins.   

Figure 1. Azure Ethereum templates

2.  Configuring the template: After the necessary template have been chosen it has to be configured. Apart from the usual Azure parameters like resource group and administrator accounts, the structure of the network has to be set, like the number and size of the mining and translation nodes. or the number of consortium members. The last tab provides the possibility to configure the Ethereum specific settings, like the network ID or a custom genesis block.    


Figure 2. Configuring the Ethereum Consortium Blockchain

3. Creation finished: If the network creation finished, the most important parameters are to be found in the result page:
- Admin-site: a general page about the status of the network, including a faucet as well to distribute some pre-allocated ether.
- RPC-Endpoint: is an important parameter for communicating with the consortium blockchain for example from Truffle or Metamask.
- SSH Info: is important for logging in into the environment and configuring parameters, like most typical for unlocking the coinbase account.

Figure 3. important parameters for accessing the consortium blockchain

4. Unlocking the coinbase account: It might cause difficulties in the future so it is not a bad idea to explicitly unlock the coinbase account. With the help of ssh and the ssh command of the previous configuration window, you can attach to the first node of the ethereum consortium network (note that usually the first node is the transaction node, if it is confidently different, you can log in into further nodes with using -p 3001 3002 ... parameters).

If you logged in, you can use: 

  geth attach  -- to attach to a running geth instance

  personal.unlockAccount(eth.coinbase) -- unlocking the coinbase account, the default unlock time is 5 minutes.

 eth.coinbase -- getting the address of the coinbase account

 personal.unlockAccount('address', 'passphrase', 'duration')  -- unlocking the account for a longer time period. If you use 0 as duration, the account will be locked forever. 

5. Configuring Metamask: Based on the Ethereum-RPC-Endpoint, Metamask can be configured with changing from the Main Network to a custom RPC. With the help of the admin page faucet and newly generated accounts, the pre-allocated ether can be further allocated and the network basic network functionality can be tested.


Figure 4. Metamask configuration

6. Deploying contract: If Metamask set up you can directly or indirectly deploy contracts with the help of remix by selecting "Injected Web3" or "Web3 Provider" at the environment. "Injected Web3" deploys the contract with the help of the configured Metamask account.


Figure 5. Remix configuration


7. Configuring Truffle for the consortium network: if you want to deploy to the new Azure consortium network, make sure that you configured the new network in the truffle.js configuration file. You can get the host name as the Ethereum-RPC-Endpoint from the output window, and you can get the network_id from the initial configuration. You can deploy on your consortium network for instance with the truffle migrate --network azureNetwork command.


Figure 6. Truffle configuration