Recipe ID: hsts-r23
We offer blockchain introduction, Hyperledger for system admin, Ethereum, Solidity, Corda R3, Hyperledger for developers, blockchain cybersecurity and more classes in self-paced video format starting at $60. Click here to learn more and register. For complete self-paced blockchain training, visit our Complete Blockchain Development Training page.
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:
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
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:
2. Perform a transaction by selecting 1. New transaction (tx). The Iroha CLI's available commands for the transaction are as follows:
3. Create the hotcoin asset in the ico domain using the Iroha CLI by selecting 14:
4. Add the hotcoin asset to the admin account by selecting option 16:
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:
6. Perform a transaction to transfer the hotcoin asset from the admin account to the user account by selecting option 5:
7. Perform a query to check the balance of the admin account and user. The balance of the admin account is now 60:
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.
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
We offer private coding classes for beginners online and offline (at our Virginia site) with custom curriculum for most of our classes for $59 per hour online or $95 per hour in virginia. Give us a call or submit our Private Coding Classes for Beginners form to discuss your needs.