企業向けスマートコントラクト「Quorum」って、Ethereumとどう違うの?Ethereumではじめる“スマートコントラクト開発”(4)(2/2 ページ)

» 2018年04月16日 05時00分 公開
[大竹祐貴トライデントアーツ]
前のページへ 1|2       

Quorumサンプルの動作

 実際にQuorumを動かしてみます。「7nodes」という、7つのノードで構成されたネットワークの動作サンプルが、GitHubで提供されており、お手軽に試すことができます。今回は、Quickstartの手順に従い進めます。

 まず、Gitをインストールし、Windows10の64bit版で環境を構築します。

 また7nodesの実行には仮想マシンを構築するソフトウェア「VirtualBox」と「Vagrant」が必要になるのでインストールします。

 今回、筆者の環境では下記バージョンを使用します。

Git for Windows: git version 2.17.0.windows.1

VirtualBox: 5.2.8

Vagrant: 2.0.3


 コマンドプロンプトを起動して、「quorum-example」リポジトリをクローンします。その後、仮想環境を稼働し、Secure Shell(SSH)にて接続します。下記のコマンドを入力します。

git clone https://github.com/jpmorganchase/quorum-examples
cd quorum-examples
vagrant up
(数分かかります)
vagrant ssh

 すると、仮想環境に接続でき、以下のような内容が表示されます。

Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-93-generic x86_64)
 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
 Get cloud support with Ubuntu Advantage Cloud Guest:
  http://www.ubuntu.com/business/services/cloud
ubuntu@ubuntu-xenial:~$

 次に、以下のコマンドを実行して、7nodesを起動します

cd quorum-examples/7nodes
./raft-init.sh
./raft-start.sh

 以下の内容が表示されれば、起動完了です。

[*] Starting Constellation nodes
[*] Starting node 1 (permissioned)
[*] Starting node 2 (permissioned)
[*] Starting node 3 (permissioned)
[*] Starting node 4 (permissioned)
[*] Starting node 5 (unpermissioned)
[*] Starting node 6 (unpermissioned)
[*] Starting node 7 (unpermissioned)
[*] Waiting for nodes to start
[*] Sending first transaction
Contract transaction send: TransactionHash: 0x2482039176ff052b6bea8102d5ce9526a45610bcb92574258ceecaeb48cc1a54 waiting to be mined...
true
All nodes configured. See 'qdata/logs' for logs, and run e.g. 'geth attach qdata/dd1/geth.ipc' to attach to the first Geth node

 QuorumはEthereumと互換性があるため、「geth」コンソールコマンドを使用することができます。試しにnode1のコンソールを起動してみます。

geth attach qdata/dd1/geth.ipc

 以下の内容が表示され、コンソールが起動します。

Welcome to the Geth JavaScript console!
instance: Geth/v1.7.2-stable-0905eda4/linux-amd64/go1.7.3
coinbase: 0xed9d02e382b34818e88b88a309c7fe71e65f419d
at block: 1 (Sun, 06 Jun 47961369058 19:05:35 UTC)
 datadir: /home/ubuntu/quorum-examples/7nodes/qdata/dd1
 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 raft:1.0 rpc:1.0 txpool:1.0 web3:1.0
>

 ここでネットワークのピアを確認してみましょう。「admin.peers」コマンドを実行します。

>admin.peers
[{
    caps: ["eth/63"],
    id: "0ba6b9f606a43a95edc6247cdb1c1e105145817be7bcafd6b2c0ba15d58145f0dc1a194f70ba73cd6f4cdd6864edc7687f311254c7555cc32e4d45aeb1b80416",
    name: "Geth/v1.7.2-stable-0905eda4/linux-amd64/go1.7.3",
    network: {
      localAddress: "127.0.0.1:59220",
      remoteAddress: "127.0.0.1:21001"
    },
    protocols: {
      eth: {
        difficulty: 0,
        head: "0xc23b4ebccc79e2636d66939924d46e618269ca1beac5cf1ec83cc862b88b1b71",
        version: 63
      }
    }
}, {
〜略〜
}, {
    caps: ["eth/63"],
    id: "eacaa74c4b0e7a9e12d2fe5fee6595eda841d6d992c35dbbcc50fcee4aa86dfbbdeff7dc7e72c2305d5a62257f82737a8cffc80474c15c611c037f52db1a3a7b",
    name: "Geth/v1.7.2-stable-0905eda4/linux-amd64/go1.7.3",
    network: {
      localAddress: "127.0.0.1:55894",
      remoteAddress: "127.0.0.1:21005"
    },
    protocols: {
      eth: {
        difficulty: 0,
        head: "0xc23b4ebccc79e2636d66939924d46e618269ca1beac5cf1ec83cc862b88b1b71",
        version: 63
      }
    }
}]
>

 6つのピアの情報が表示され、自ノード(node1)を含めて7つのノードで構成されていることを確認できます。

 exitコマンドでnode1のコンソールを抜けます。

> exit

 「7nodes」を停止させるには、同ディレクトリにある「stop.sh」を実行します。

./stop.sh

 実行時に「bootnode: no process found」と表示されますが、問題はありません。シェルスクリプトでは「bootnode」というプロセスを停止する記述がありますが、7nodesのサンプルでは、そもそもbootnodeを起動していません(以前の7nodesではbootnodeを起動していたため、その名残だと思われます)


 いかがでしたか。このように、サンプルを使うことで、Quorumを簡単に動かせます。

 次回は、7nodesの環境を使用して、プライベートトランザクションを実行する方法を紹介します。

著者プロフィール

大竹祐貴

トライデントアーツ株式会社

「一歩先の技術によって社会を豊かに」をテーマに、生涯現役エンジニアとして貢献すべく、ブロックチェーンを活用したアプリケーションの開発を務める。現在はInterledger Protocolを活用したサービスの設計、開発を進めている。


前のページへ 1|2       

Copyright © ITmedia, Inc. All Rights Reserved.

RSSについて

アイティメディアIDについて

メールマガジン登録

@ITのメールマガジンは、 もちろん、すべて無料です。ぜひメールマガジンをご購読ください。