2. С чего начать¶
В этом руководстве мы создадим очень простую сеть Iroha, запустим ее, выполним несколько транзакций и проверим данные, записанные в блокчейн. Для того, чтобы максимально упростить процесс, мы будем использовать 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.
For this guide, you need a machine with
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. Starting Iroha Node¶
2.2.1. Creating a Docker Network¶
To operate, Iroha requires a
Let’s start with creating a Docker network, so containers for Postgres and
Iroha can run on the same virtual network and successfully communicate.
In this guide we will call it
iroha-network, but you can use any name.
In your terminal write following command:
docker network create iroha-network
2.2.2. Starting PostgreSQL Container¶
Now we need to run
PostgreSQL in a container, attach it to the network
you have created before, and expose ports for communication:
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:
2.2.3. Creating 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 Deploying Iroha
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. Starting Iroha Container¶
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
-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-networkfor 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:latestis 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.