Create Cryptocurrency Using Hyperledger Iroha CLI


Create Cryptocurrency Using Hyperledger Iroha CLI

Recipe ID: hsts-r23


Recipe Overview

Hyperledger Iroha is a general-purpose permissioned blockchain system hosted by The Linux Foundation. It was contributed by Soramitsu, Hitachi, NTT DATA, and Colu. Hyperledger Iroha is written in C++ and incorporates the BFT consensus algorithm, named Yet Another Consensus (YAC). Hyperledger Iroha consists of simple deployment and fast development. It can be used in applications that manage digital assets, identity, interbank payment, and so on.

For those who are not familiar with Hyperledger project Intro to Hyperledger Family and Hyperledger Blockchain Ecosystem and Hyperledger Design Philosophy and Framework Architecture articles are strongly recommended.

To better follow and understand this recipe, it is advisable to read and follow Install Hyperledger Iroha on AWS and Configuring Hyperledger Iroha Peer Node and Network recipes in advance. Specifically, in our last recipe, we learned how to configure the Iroha peer node and define the domain, role, permission, and account for the Iroha network. However, in this recipe we will explore the Iroha Command Line Interface or CLI.
The Iroha CLI is interactive and flexible, which offers common and basic functions to manage network peers, domains, accounts, assets, and perform transactions and queries to work with the Iroha network.
In this recipe, we will utilize the Iroha CLI to perform the following transactions to demonstrate the ready-to-use asset and account management solution and functionalities offered by Iroha:

Iroha Docker Container Configuration

Perform the following steps before moving ahead:

1. Go to the bash Iroha container:
sudo docker exec -it iroha /bin/bash

2. Update the test domain ID to ico using nano in the genesis.block configuration file. Rename the sample key files to ico. For the sake of simplicity, we do not generate private and public key files for this recipe and we reuse the key files from Iroha examples. However, in real usage, all key files for accounts and peers should be generated as follows:

root@b551830ade0e:/opt/iroha_data# mv admin@test.priv admin@ico.priv
root@b551830ade0e:/opt/iroha_data# mv admin@test.pub admin@ico.pub root@b551830ade0e:/opt/iroha_data# mv test@test.priv user@ico.priv root@b551830ade0e:/opt/iroha_data# mv test@test.pub user@ico.pub

3. Start the Iroha daemon node using the following command:
irohad --config config.docker --genesis_block genesis.block -- keypair_name node0

 

Create Cryptocurrency with Hyperledger Iroha CLI

Execute the following steps to create cryptocurrency using CLI:

1. Run the Iroha CLI:
iroha-cli -account_name admin@ico

The options that are available on the Iroha CLI menu are as follows:
Hyperledger Iroha CLI 1

 

2. Perform a transaction by selecting 1. New transaction (tx). The Iroha CLI's available commands for the transaction are as follows:
Hyperledger Iroha CLI 2

 

3. Create the hotcoin asset in the ico domain using the Iroha CLI by selecting 14:
Hyperledger Iroha CLI 3

 

4. Add the hotcoin asset to the admin account by selecting option 16:
Hyperledger Iroha CLI 4

 

5. Perform a query to check the coin balance of the admin account. This can be done by selecting the first option, 2. New query (qry), and the 8. Get Account's Assets (get_acc_ast) option. The Iroha CLI's available queries are as follows:
Hyperledger Iroha CLI 5

6. Perform a transaction to transfer the hotcoin asset from the admin account to the user account by selecting option 5:
Hyperledger Iroha CLI 6

 

7. Perform a query to check the balance of the admin account and user. The balance of the admin account is now 60:
Hyperledger Iroha CLI 7

Put Things Together

In this recipe, we set up the domain, account, and role in the Iroha genesis.block file to start a new Iroha network. We also performed different transactions, such as creating an asset, transferring the asset into an account, and querying account balance using the Iroha CLI. The Iroha CLI utilizes a set of Iroha pre-built commands and queries, which are smart contracts on the block chain. Providing pre-built common smart contracts is not only safer, as they are tested and verified by the Iroha community, but it also provides an out-of-the-box solution for small-scale blockchain DApps. You could easily and quickly build the blockchain network and start to create assets, accounts, and perform basic CRUD tractions for your organization.
Iroha commands are smart contracts that perform an action to change the state of an asset and account in Iroha WSV. Commands are applied to the blockchain network using a transaction. The Iroha peer then validates and changes the current state in the WSV, which is the snapshot of the system. Multiple transactions are composed into a block and persisted into the immutable block store, which is used to keep the history of the transactions.
Iroha supports both single and batch transactions. Transactions can consist of one or many commands that will be performed in order and atomically.
The Iroha transaction basic payload and proto definition are as follows:

Command can be defined as follows:

message ReducedPayload{

repeated Command commands = 1;
string creator_account_id = 2;
uint64 created_time = 3;
uint32 quorum = 4;

}


Accounts and assets are basic models in the command. The name format to refer to an account is accountid@domain, and the name format to refer to an asset is assetid#domain. The following commands are implemented in the current Iroha release, and they offer basic CRUD actions for domain, account, asset, role, and permission, as well as their proto definition:

message Command {

oneof command {

AddAssetQuantity add_asset_quantity = 1; AddPeer add_peer = 2;
AddSignatory add_signatory = 3;
AppendRole append_role = 4;
CreateAccount create_account = 5;
CreateAsset create_asset = 6;
CreateDomain create_domain = 7;
CreateRole create_role = 8;
DetachRole detach_role = 9;
GrantPermission grant_permission = 10;
RemoveSignatory remove_sign = 11;
RevokePermission revoke_permission = 12;
SetAccountDetail set_account_detail = 13;
SetAccountQuorum set_quorum = 14;
SubtractAssetQuantity subtract_asset_quantity = 15;
TransferAsset transfer_asset = 16;

}

Query is the smart contract that is used to request the current state of the system, and it does not update the state. Its basic payload and proto definition are as follows:

Query can be defined as follows:

message QueryPayloadMeta {

uint64 created_time = 1;
string creator_account_id = 2;

}

Iroha provides the following built-in queries to inquire about the status of an account, asset, role, and transaction. The query proto definitions are as follows:

message Query {

message Payload {

QueryPayloadMeta meta = 1;

oneof query {

GetAccount get_account = 3;
GetSignatories get_account_signatories = 4;
GetAccountTransactions get_account_transactions = 5;
GetAccountAssetTransactions get_account_asset_transactions = 6;
GetTransactions get_transactions = 7;
GetAccountAssets get_account_assets = 8;
GetAccountDetail get_account_detail = 9;
GetRoles get_roles = 10;
GetRolePermissions get_role_permissions = 11;
GetAssetInfo get_asset_info = 12;
GetPendingTransactions get_pending_transactions = 13;

}

}
Additional insights
The Iroha CLI also provides the functionality to generate key pairs for accounts and so on in the network. You can run this to generate key pairs for admin and user accounts in this recipe rather than using example Iroha key pairs. In a real case, you should choose the secure approach to generate keys for your application.
To generate a public and private key pair to identify a new account, enter the Iroha CLI command, as follows:

root@b551830ade0e:/opt/iroha_data# iroha-cli --new_account --account_name newuser@ico --pass_phrase newuserpassphrase --key_path ./
[2018-11-18 17:03:19.877331834][th:358][info] CLI-MAIN Public and private key has been generated in current directory

The following recipes are excellent resources for installing other Hyperledger tools:
Blockchain Developer Guide- Overview of Hyperledger Explorer and its Development Environment
Blockchain Developer Guide- How to Install Hyperledger Fabric on AWS
Blockchain Hyperledger Composer Business Network Modeling and Environment Setup
Blockchain Developer Guide- How to Install Hyperledger Indy and Indy CLI on AWS

To conclude this recipe, we like to recommend our Learn Hands-on Blockchain Ethereum Development & Get Certified in 30 Hrs and Blockchain Hyperledger Development in 30 hours courses to those interested in pursuing a blockchain development career. Indeed, as of this writing, Hyperledger Foundation offers the following two Hyperledger certifications: The Certified Hyperledger Fabric Administrator (CHFA) and The Certified Hyperledger Sawtooth Administrator (CHSA), both of which are highly regarded in the industry. Hyperledger Foundation is in the process of creating Hyperledger Developer certification program, which may be released in early or middle of 2020. In short, by taking our hands-on online Hyperledger class, you would be able to obtain CHFA certification.

This tutorial is written by Brian Wu who is our senior Hyperledger instructor in Washington DC. His Hyperledger Cookbook with 40+ hands-on recipes is highly recommended.

Related Training Courses

Hands-on Node.JS, MongoDB and Express.js Training
Advance JavaScript, jQuery Using JSON and Ajax
Learn Hands-on Blockchain Ethereum Development & Get Certified in 30 Hrs
Learn Blockchain Hyperledger Development & Get Certified in 30 Hrs
Become Blockchain Certified Security Architect in 30 hours
Blockchain Certified Solution Architect in 30 hours
Introduction to Python Programming
Object Oriented Programming with UML


Private and Custom Tutoring

We provide private tutoring classes online and offline (at our DC site or your preferred location) with custom curriculum for almost all of our classes for $50 per hour online or $75 per hour in DC. Give us a call or submit our private tutoring registration form to discuss your needs.


View Other Classes!