2. はじめる

このガイドでは、基本的ないろはネットワークを作成し、立ち上げ、いくつかのトランザクションを作成し、台帳に記録されたデータを確認します。 単純にするために、Dockerを利用します。

注釈

Ledger is the synonym for a blockchain, and Hyperledger Iroha is known also as Distributed Ledger Technology framework — which in essence is the same as "blockchain framework". You can check the rest of terminology used in the 重要事項 section.

2.1. 前提となる環境

For this guide, you need a machine with Docker installed. You can read how to install it on a Docker's website.

注釈

Of course you can build Iroha from scratch, modify its code and launch a customized node! If you are curious how to do that — you can check Building Iroha section. In this guide we will use a standard distribution of Iroha available as a docker image.

2.2. いろはノードを起動する

2.2.1. Dockerネットワークを作成する

Irohaが動作するためには PostgreSQL データベースが必要です。 PostgresとIroha用のコンテナが同じ仮想ネットワーク上で実行され、正常に通信が行われるようにするため、まずはDockerネットワークの作成から始めましょう。 本ガイドでは、「iroha-network」と呼んでいますが、任意の名前を使用することができます。任意の名前を使用するためには、ターミナル上で次のコマンドを実行します。

docker network create iroha-network

2.2.2. PostgreSQLのコンテナを起動する

では次に、コンテナ内でPostgreSQLを実行し、これまでに作成したネットワークに接続し、通信用ポートを公開します。これらのステップを以下に示します。

docker run --name some-postgres \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=mysecretpassword \
-p 5432:5432 \
--network=iroha-network \
-d postgres:9.5 \
-c 'max_prepared_transactions=100'

注釈

If you already have Postgres running on a host system on default port (5432), then you should pick another free port that will be occupied. For example, 5433: -p 5433:5432

2.2.3. Blockstoreを作成する

Before we run Iroha container, we may create a persistent volume to store files, storing blocks for the chain. It is done via the following command:

docker volume create blockstore

2.2.4. Preparing the configuration files

注釈

To keep things simple, in this guide we will create a network containing only a single node. To understand how to run several peers, follow いろはを運用・導入する

Now we need to configure our Iroha network. This includes creating a configuration file, generating keypairs for a users, writing a list of peers and creating a genesis block.

Don't be scared away — we have prepared an example configuration for this guide, so you can start testing Iroha node now. In order to get those files, you need to clone the Iroha repository from Github or copy them manually (cloning is faster, though).

git clone -b master https://github.com/hyperledger/iroha --depth=1

ヒント

--depth=1 option allows us to download only the latest commit and save some time and bandwidth. If you want to get a full commit history, you can omit this option.

There is a guide on how to set up the parameters and tune them with respect to your environment and load expectations: 設定. We don't need to do this at the moment.

2.2.5. Irohaコンテナを起動する

We are almost ready to launch our Iroha container. You just need to know the path to configuration files (from the step above).

Let's start Iroha node in Docker container with the following command:

docker run --name iroha \
-d \
-p 50051:50051 \
-v $(pwd)/iroha/example:/opt/iroha_data \
-v blockstore:/tmp/block_store \
--network=iroha-network \
-e KEY='node0' \
hyperledger/iroha:latest

If you started the node successfully you would see the container id in the same console where you started the container.

Let's look in details what this command does:

  • docker run --name iroha \ creates a container iroha
  • -d \ runs container in the background
  • -p 50051:50051 \ exposes a port for communication with a client (we will use this later)
  • -v YOUR_PATH_TO_CONF_FILES:/opt/iroha_data \ is how we pass our configuration files to docker container. The example directory is indicated in the code block above.
  • -v blockstore:/tmp/block_store \ adds persistent block storage (Docker volume) to a container, so that the blocks aren't lost after we stop the container
  • --network=iroha-network \ adds our container to previously created iroha-network for communication with PostgreSQL server
  • -e KEY='node0' \ - here please indicate a key name that will identify the node allowing it to confirm operations. The keys should be placed in the directory with configuration files mentioned above.
  • hyperledger/iroha:latest is a reference to the image pointing to the latest release

You can check the logs by running docker logs iroha.

You can try using one of sample guides in order to send some transactions to Iroha and query its state.