NEM LIFE

nem、xemに関する最新のニュースを翻訳してお届けします!

NEM2ブロックチェーンの使用方法は?

以下は下記記事を和訳したものです。
https://nemflash.io/integrating-nem2-blockchain/

ブロックチェーンの使用方法は?
ジュリアン 2019年1月23日

f:id:jijikokkoku:20190131132930p:plain

 こんにちは、読者の皆さん。分散台帳のテクノロジーの分野で、今日別の旅に出るため私たちをフォローしてください。今日、私たちはソフトウェアにNEM2ブロックチェーン・プロトコルを統合します。

 NEMは2015年3月から存在するブロックチェーンですが、2018年7月から別名カタパルトと呼ばれる、NEM2ブロックチェーンを試すことが可能になっています。

 本記事では、私たちはNEM2ブロックチェーンのオープンソース・パッケージの使用方法に関するいくつかの例を見ていきます。これから使用する予定のパッケージのほとんどがまだ開発中で、動作は時間とともに変化する可能性があります。

 さらに私たちは、api.beta.catapult.mijin.io:3000でAPIノードを使用する予定です。このAPIノードは、現在展開されているNEM2バージョンを変更し、ここに登録されている機能のいくつかを互換性のない状態にする可能性があります。これはこの記事を読みやすくし、最新分析のNEM2ソフトウェアを使用するためです。

私たちのツールセットを定義する
 お使いのワークステーションを設定するガイドに記載されている、NEMスタートガイドで定義されている通り、私たちはnem2-cliのパッケージをインストールする予定です。

 NEM2ネットワークを起動するために、私たちはapi.beta.catapult.mijin.io:3000というAPIノードを使用する予定です。これはNEM2ブロックチェーンを開始し、作業するために必要なものです。

 仲間とやりとりできる、nem2-cliパッケージをインストールしましょう。

$ npm install -g nem2-cli

アカウントを作成し、作成したアカウントのブロックチェーン上でトランザクションを監視することで締めくくられる、いくつかのコマンドから開始しましょう。
デフォルトでは、nem2-cliは常にデフォルトのプロファイルを使用しますが、管理するものが複数ある場合、ユーザーはこれらに名前を付けることもできます。以下は、最初のNEM2ウォレットアドレスを作成するためのコマンドです。このコマンドは、現在展開されている最新のNEM2 リリースとやり取りするために使用できます。

$ nem2-cli account generate -n MIJIN_TEST –save -u http://api.beta.catapult.mijin.io:3000

 新しい秘密鍵、公開鍵、アドレスを書き留めてください。

 上記のコマンドは、nem2-cliでデフォルトのプロファイルへアカウントを保存します。アカウントを作成し、別の名前のプロファイルにインポートしたい場合、nem2-cliコマンドに–profileの実引数を追加してください。

 名前を付けたプロファイルを使用し、接続された仲間およびネットワークごとに利用可能なアドレスの、より優れた概要を保つことを強くお勧めします。

NEM2とのやり取り
 
 次の手順として、私たちは現在、ブロックチェーンの「ブロックの高さ」を読むことができます。次のコマンドが、必要なマジックのすべてです。

$ nem2-cli blockchain height

nem2-cliを使用すると、NEM2ネットワークに必要な数多くのことを実行できます。次のセクションでは、実際にこのツールの数例を見ていきたいと思います。

現在のカタパルトベータ版で資金をリクエストする

 NEM2は、プル・トランザクションを使用してモザイクバランスをフィードするため、驚くべきツールを私たちに与えてくれます。リクエストは私たちのアカウントから送信され、支払人はトランザクションに連署する必要があります。

 最初の段階として、私たちはカタパルトウェブサイト上でパブリックベータ・フォーセットから資金をリクエストします。カタパルトベータのウェブサイトへ移動し、新しく作成したアドレスに資金をリクエストしてください。15分間待つと(次のブロック)、お使いのアカウントに10’000 XEMが振り込まれるはずです。金額は変わる場合もあります。

 2つ目のアドレスを作成し、アカウント作成コマンドを繰り返し、新しい秘密鍵とアドレスを書き留めてください。このアドレスは、2つ目のアカウントとして参照されます。

 アカウント作成コマンドは常にプロファイル名を設定するように要求しますので、プロファイルに人が読みやすい名前を設定し、これらを整理できるよう確認することをお勧めします。

 たとえば、今回名前をsecond_accountと設定するとします。こうすると、nem2-cli commandsに–profile second_accountを追加するときはいつでも、署名やプロパティに2つ目のアカウントを使用していることになります。

nem2-cli account generate -n MIJIN_TEST –save -u http://api.beta.catapult.mijin.io:3000


 nem2-cliプロファイルリストを起動して、アカウントを作成しているか確認できます。リストの中には現在2つのプロファイルがあるはずで、それぞれ以下に表示されているように1つ目(デフォルト)のプロファイルと、second_accountプロファイルです。

f:id:jijikokkoku:20190131133229p:plain

参考例として作成したプロファイルのリスト

 以下のセクションは、同様の資金リクエストを発行しますが、ターミナルからnem2-cliを使用して、作成した2つ目のアカウントを手動で発行できます。

プル・トランザクションを使用して、手動で資金をリクエストする
 さて、ウェブサイト上でこのアクションが実行するのは、2つ目のアカウントで資金をリクエストするため、プル・トランザクションを発行することです。

 nem2-cliツールセットを使用して、このようなプル・トランザクションの発行は、以下のコマンドから実行できます。

$> nem2-cli transaction pullfunds –recipient SDUFICQAIHN2VYORJILRQ5YXAERLJF5HDTPJNXVR –message “please send me 5 XEM” –mosaic nem:xem::5000000 –profile second_account


 このコマンドを実行した場合SDUFICQAIHN2VYORJILRQ5YXAERLJF5HDTPJNXVRというアカウントから5 XEMをリクエストします。出力結果として、以下のような画面が確認できます。

f:id:jijikokkoku:20190131133250p:plain

HashLockトランザクションの結果(1つ目)と通知されたプル・トランザクション(2つ目)

ここで確認できる2つ目のハッシュを書き留めてください。これは連署する必要があるトランザクション・ハッシュで、実行するとプル・トランザクションが有効になります。これを実行するため、nem2-cliで利用可能な連署モジュールを使用します。

 以下は、上記スクリーンショットからの数値の例です。

$ nem2-cli transaction cosign –hash B4A4495E138869871F38E5643D2A4935E4140FA3205065827419024EFCD664D8 –profile default



 これは私たちのデフォルトプロファイルで連署トランザクションを発行し、資金のリクエストを確認します。api.beta.catapult.mijin.ioを使用する際、Block Explorerを使用してお使いのトランザクションを見ることができます。

 プル・トランザクションは現在実行中で、お使いの2つ目のアカウントでリクエストした資金を使用することができます。さて、楽しくなってきましたね?今ではどのアカウントからでも、トランザクションに連署する必要のある関係するすべてのアカウントからでも、どのモザイクもリクエストが可能です。

 NEM2で利用可能なプルファンド・トランザクションは、イノベーティブなビジネスユースケースの扉を開きます。私たちはNEMエクスペリエンスの一部になることにとてもワクワクしていますし、これをリサーチし、使用して、分析したいと思っています。資金のリクエストは、NEM2で可能になったトランザクションの1種類に過ぎません。さらに知りたい方はこの先を読み進めてください!

トークンを送受信
 私たちは既に、アカウントに資金を調達するためのさらに複雑な送金方法を知っています。 私たちは現在、簡単な送金方法を開始し、アカウントの残高について情報を得ています。

 私たちは、1つ目のアカウントから2つ目のアカウントへの送金トランザクションを作成します。この送金トランザクションは、2つ目のアカウントに1 XEMを送金し、コンテンツにメッセージを添付します。「NEM 2へようこそ」

 nem2-cliでは、実行するコマンドは1つだけになる予定です。私たちは以下のコマンドで示されているように、トランザクションに受信者、金額、メッセージを設定する必要があります。ADDRESS_SECOND_ACCOUNTを、アドレスと一緒に新しく作成した2つ目のアカウントに置き換えてください。

 $ nem2-cli transaction transfer –recipient ADDRESS_SECOND_ACCOUNT –message “Welcome to NEM2.” –mosaics nem:xem::1000000

 

 1’000’000の金額に注目してください。これは私たちが送金する金額を表し、XEMモザイクの最小単位になります。XEMの金額には6つの可分性があり、これは私たちが1 XEMを送金する場合、6つのゼロを付け足す必要があることを表します。

 最初の方の例では、私たちは5’000’000の額の送金をリクエストしましたが、ここで適用されるのも同じ原理です。私たちはXEMをリクエストしているので、0.000005 XEMではなく5 XEMをリクエストするためにゼロを6つ、付け足します。これで私たちは2つ目のアカウントに送金できました。2つ目のアカウントをモニターし、アカウントの残高について情報を入手しましょう。

NEM2アカウントをモニターする

 さらに言えば、nem2-cliはこのタスクに最適です。以下のコマンドは、NEN2ネットワーク上で述べたアカウントのトランザクションをモニターするのに使用できます。

$ nem2-cli monitor confirmed –address ADDRESS_SECOND_ACCOUNT

 トランザクションが確認されると、アカウントの状態が更新されます。これは2つ目のアカウントにXEMの残高が増えたということを意味します。

 NEM2 APIを認証し、以下のコマンドを実行して、アカウント情報を閲覧しましょう。

$ nem2-cli account info –address ADDRESS_SECOND_ACCOUNT

 以下の画面のような情報が入手できるはずです。

f:id:jijikokkoku:20190131133346p:plain

nem:xem残高のアカウント情報結果の例

 nem2-cliアカウントモジュールを見つけ出すのに、情報コマンド以外の方法があります。以下は、お使いのアカウント状態についていくつかの情報を閲覧するのに実行する、有効なコマンドです。

$ nem2-cli account info –address ADDRESS
$ nem2-cli account transactions –publickey PUBLIC_KEY
$ nem2-cli account incoming –publickey PUBLIC_KEY
$ nem2-cli account outgoing –publickey PUBLIC_KEY
$ nem2-cli account aggregatebonded –publickey PUBLIC_KEY
$ nem2-cli account unconfirmed –publickey PUBLIC_KEY

 公開鍵を書き留めなかった場合は、nem2-cliプロファイルリストのコマンドにいつでも戻ることができ、保存したキーすべての概要を確認できます。

 これらのコマンドで、アカウントの状態をとても簡単にモニターできます。nem2-cliとnem2-sdkのソースコードパッケージを閲覧し、NEM2 APIについて詳細を入手しましょう。

NEM2についてほかに知るべきことは?
 NEM2は、アーキテクチャとソースコードをゼロから開始し、ブロックチェーン分野の最新イノベーションが付属した、高度なブロックチェーン・システムです。

NEM2ブロックチェーンの高度な機能は、以下を含みますがそれ以外にもあります。

■トークンのアトミックスワップ
■マルチレベルのマルチシグネチャアカウント
■スマートアセットシステム
■アグリゲート・トランザクション

 複雑化する前に、これらの各イノベーションをリサーチし、ビジネスロジックへの使用方法または統合方法を定義しましょう。

アトミックトークンスワップ
 ブロックチェーンおよび暗号通貨は、ただ数値をより速く送金するための扉を開いただけではありません。NEM2のようなブロックチェーン・プラットフォームでは、分散方式で数値を維持しながら、コントラクトを実行することが可能です。しかもこれらのコントラクトは、アトミック操作が可能です。

 私たちは原子について話しているわけではなく、トランザクションの不可分性について話しています。アトミック・トランザクションが何を表しているか即座にリサーチすると、以下のことがわかります。

 「アトミック・トランザクションは、すべて実行されている、または実行されていない不可分の、またはこれ以上単純化できない一連のデータペース操作である」

 この引用の中の、「データベース操作」を「アカウント・トランザクション」に置き換えてみてください。アトミックトークンスワップは、すべて実行しているまたはすべて実行していない状態でも、複数のトランザクションを実行します。

 これは多くの場合、とても役立ちます。たとえば、2種類の異なるブロックチェーン・ネットワーク(トークンスワップ)間で、数値を送信する場合などです。いわゆるクロスチェーン・トークンスワップが、現在のNEM2テクノロジーで実行可能で、私たちは今後の記事で、これらを実行する方法を紹介する予定です!

 暗号通貨ドメイン以外のほかの役立つ例は、数多くの姉妹企業で自動オフィスへのアクセスを容易化し管理する、ブロックチェーンの使用です。プライベートブロックチェーンは、機微のデータを個人的に管理するために使用されますが、姉妹企業はアクセスデータベースとして、1つの共通の分散台帳を共有できます。

 これらのユースケースの内いくつかは、ビジネスロジックの異なるコンポーネントを表すため、複数の暗号通貨を発行する必要があるはずです。私たちは今日、デジタル化を数多くの局面で起こす必要があることを確認できます。

 私たちの自動オフィス・ユースケースでは、アトミックスワップはインターネットに接続されたデバイス(IoT)間で通信レイヤーとなり、数値を交換して、異なるプラットフォーム上で数値を維持したままデジタル化した取引を実行できます。

マルチレベルのマルチシグネチャ
 NEM2のマルチシグネチャ・トランザクションは、単純さと強力さを一つにします。お使いのマルチシグネチャアカウントに連署者の全体の階層構造を定義できます。


 マルチレベルのマルチシグネチャアカウントの一例として、私たちは今後のリリースに向けて、ソフトウェア企業の分散決定木を定義できます。関係のある各アカウントは、私たちが最初の方で作成したNEM2アカウントです。以下のスキーマを例として挙げましょう。

f:id:jijikokkoku:20190131133502p:plain

各部門はそれぞれマルチシグネチャアカウントを持ち、従業員は連署者となっている。

 この場合、マルチシグネチャの構造は単純です。階層構造の一番上に位置するマルチシグネチャアカウントは、3つの内3つのマルチシグネチャアカウントです。これは3つすべてのチーム(マーケティングチーム、ファイナンスチーム、開発者チーム)が、それぞれの連署の最小番号でリリースを確認する必要があることを意味します。

 たとえば、開発者チームの内2名がリリースを安全ではないと定義した場合、彼らはリリース公開トランザクションに連署しないはずです。これにより公開が起きないようにします。このような構造で、数多くのデジタル化された企業は自動的に管理されます。組織、オフィス、企業、家屋、施設なども同様です。

 日常生活の数多くのことが、まだこれに対応するデジタル化されたものが発見されていません。

スマートアセットシステム
 スマートアセットシステムとは正確に何を表しているのでしょうか?スマートという単語で作成された単なるバズマーケティングでしょうか?ですが、ご覧の通りNEM2では、アセットは確かにスマートです。これらはサプライの可変性、可分性(小数点以下の桁数)、ダイナミック手数料(いわゆる課税料金)などのプロパティを設定可能です。

 NEM2には、改善されたネームスペースとモザイクモジュールが付属しています。NEM上のモザイクは、パブリックネットワークで作成されたカスタムトークンです。NEM2上では、同様に自分のモザイクを発行可能です。ネーム登録以外にもほかの数多くの機能で、ネームスペースとモザイクはお使いのブロックチェーン機能とよく似ています。

 NEM2では、お使いのすべてのビジネスロジックを再定義する面倒なしで、カスタムトークンを管理する必要のあるすべてのAPIエンドポイントをご利用になれます。

 NEMの以前のバージョン(NIS1)で既によくあったように、NEM2は、強力なアグリゲート・トランザクションを持つ、機能群が付属しています。これは基本的にどの種類のビジネスフローでも(さらにお使いのどのカスタムトークンでも)作成する指示を出し、これらをアトミックにし共有できるようにします。

アグリゲート・トランザクション
 アグリゲート・トランザクションを表す最も簡単な定義は、これらはトランザクション・ラッパーであり、15種類の異なるアカウントまで含むことができ、1000種類の内部トランザクションを保有することができる、というものです。

 このシステムは現在、マルチシグネチャのプッシュ通知を有効にすることにも使用されています。実際、NEM2を使用すると、アグリゲートボンドトランザクションを作成できます。これらは、連署を待機中の複数または一つのトランザクションです。

 このように、NEM2ではマルチシグネチャがアカウントに特化して改善されたわけではありません。たとえば、アグリゲートボンドトランザクションには、2種類の異なるアカウントから2種類の送金方法があります。このトランザクションには、アグリゲートボンドに連署する2種類のアカウントが必要です。

 内部トランザクションは、すべての必要な連署がプッシュ通知された場合のみ、すべてが同時に実行されます。さらに、これに関する潜在的ユースケースは定義されませんが、nem.ioウェブサイト上でこの可能性に関するクイックオーバービューを閲覧できます。

 この記事では、私たちは既にアグリゲート・トランザクションを使用しました。手動で資金をリクエストする際、私たちは実際1種類以上のトランザクションを作成したことになります。合計で、3種類のトランザクションを作成しました。その内2種類には、下記リストのアグリゲート・トランザクションが含まれています。

We created a Hash Lock transaction with 10 XEM inside. This is required by the NEM2 network to prevent spamming.
We created an Aggregate Bonded transaction with 5 XEM inside.
A first inner transaction holding a message to ask for funds
A second inner transaction holding the funds we requested

 アグリゲート・トランザクションの利点は、これらの内部トランザクションが一度に実行されることです。複数の因子が関係し、アグリゲートボンドトランザクションを操作します。これらの内それぞれで、必要な動作が通知されます。

 アグリゲート・トランザクションの非常に強力な機能の一つは、nemtech githubのページ上で説明されているように、クロスチェーン・トークンスワップの例になります。

 以前モザイクを作成した初期NEMberに向けて。モザイクを作成し、株主にXEM手数料をお支払いすることで、モザイクを機能させるためにXEMを購入する必要がなくなるところを想像してみてください。NEM2のアグリゲート・トランザクションを使用すると、これは実際、非常に簡単です。

結論
 NEM2ソフトウェアはまだ開発中ですが、イノベーティブなアイデアを、積極的に改善中のブロックチェーン・プロトコルに応じた基準で実行できます。

 NEM2を構築することは簡単なままで、統合のためにビジネスロジックの変更を獲得せずに、お使いのビジネスロジックに非常に良く適合します。

 NEM2には、質的に審査されたソースコードと、NEM2の仕事を楽しいものにする評判の良いアーキテクチャ層が付属しています。

 Github上で利用可能なNEM2リポジトリをご一読ください。




nemtech: The NEM2 Github組織
catapult-server: ピアツーピアのリファレンス実装
catapult-rest: The RESTful APIリファレンス実装
nem2-docs: ドキュメンテーション・パッケージ
community: オープンソースNEM2コミュニティーで仕事をする方法

 これらのコース以外にもたくさんありますが、これらは現在この記事で書くことができる、より積極的に機能中のレポジトリです。

 この記事に関するターミナルコマンドの完全な履歴は、Githubで見つけられます。この記事を楽しんでくださっていることを心から期待していますし、フィードバックを読むことも歓迎です!私たちのウェブサイトまたはソーシャルメディアプラットフォームで、お気軽にご連絡ください。

 「NEM2は、ブロックチェーンとやり取りする方法を大改革します!」

 #NEMJoyもお忘れなく!

以下原文

How to use the NEM2 blockchain?
BY JULIAN · JANUARY 23, 2019

First appeared on eVias by Greg
Hello fellow readers, follow us today on another journey in the field of distributed ledger technology. Today, we will integrate the NEM2 blockchain protocol into our software.
NEM is a blockchain that exists since March 2015 but since July of 2018, it is possible to experiment with the NEM2 blockchain, aka Catapult.
In this article, we will go through a few simple examples of usage for the NEM2 blockchain open source packages. Most of the packages we are going to use are still under active development and behaviour might change over time.
Additionally, we will be using the API node at: api.beta.catapult.mijin.io:3000, which may change the current deployed NEM2 version making some of the features listed here incompatible. This is to keep this article simple enough and to use the latest vetted NEM2 software.
Defining our Toolset
As defined in the getting started guide on the NEM website in the guide to setup your workstation, we will be installing the nem2-cli package.
In order to have a running NEM2 network we will be using the api.beta.catapult.mijin.io:3000 API node. This is all we need to get started and work with the NEM2 blockchain.
Let us now install the nem2-cli package which will let us interact with our peers.
$ npm install -g nem2-cli
Let us start with a few commands to create an account and end with monitoring transactions on the blockchain for the created account.
By default, nem2-cli will always use a default profile but you can also name those if you have multiple to manage. So following is the command to create your first NEM2 wallet address which you can use to interact with the latest NEM2 release currently deployed.
$ nem2-cli account generate -n MIJIN_TEST –save -u http://api.beta.catapult.mijin.io:3000
Note down your new private key, public key and address.
The command above will save the account to the default profile in nem2-cli. In case you wish to generate the account and import it into a different named profile, just add the –profileargument to nem2-cli commands.
We strongly recommend to use named profiles to keep a better overview of connected peers and available addresses per network.
Interacting with NEM2
As a next step, we can now read the block height of our blockchain. Following command is all the magic that is needed:
$ nem2-cli blockchain height
Using the nem2-cli you can do pretty much anything that you need with the NEM2 network. In the next section, we will see a few examples of this tool in practise.
Request funds on the current Catapult Beta
NEM2 gives us an amazing tool to feed our mosaic balances with Pull Transactions. Those let us request a certain amount of a given mosaic for our account. The request is sent from our account and the payer must co-sign the transaction.
As a first step, we will request funds from the public beta faucet on the Catapult website. Step over to the website of the Catapult Beta and request funds to your newly created address. Wait up to 15 seconds (next block) and your account should have been funded with 10’000 XEM. This amount is subject to change.
Let us now generate a second address, re-iterate the account generation command and note down the new private key and address. This address will be referred to as the second account.
The account generate command always asks you to set a profile name, we recommend to set human readable names to your profiles to make sure you keep them organised.
For instance, this time you would set as name second_account. This way, whenever you add –profile second_account to any nem2-cli commands, you would be using the second account for signing and properties.
nem2-cli account generate -n MIJIN_TEST –save -u http://api.beta.catapult.mijin.io:3000
You can check that the account was created by running nem2-cli profile list. You should now have two profiles in that list being our first (default) profile and the second_account profile, as shown below:
List of profiles created for our example.
Following section will let you issue a similar request of funds, but manually, with your terminal using nem2-cli and the second account that we created.
Request funds manually with a Pull Transaction
Now what this action on the website actually does, is to issue a Pull Transaction as to request funds for our second account.
With the nem2-cli toolset, issuing such a pull transaction can be done with the following command:
$> nem2-cli transaction pullfunds –recipient SDUFICQAIHN2VYORJILRQ5YXAERLJF5HDTPJNXVR –message “please send me 5 XEM” –mosaic nem:xem::5000000 –profile second_account
If you execute this command, it will request 5 XEM from the account SDUFICQAIHN2VYORJILRQ5YXAERLJF5HDTPJNXVR. You should see something like this as the output:
Result for HashLock transaction (first) and announced Pull transaction (second)
Note down the second Hash you can see there. This is the transaction hash that must be co-signed before the pull transaction is effective. For this, we will use the co-signature module available in nem2-cli.
Following is an example with the values from the screenshot above:
$ nem2-cli transaction cosign –hash B4A4495E138869871F38E5643D2A4935E4140FA3205065827419024EFCD664D8 –profile default
This will issue a co-signature transaction with our defaultprofile to confirm the funds request. You can use the Block Explorer to watch your transactions when using api.beta.catapult.mijin.io.
The pull transaction is now being executed, and you can use the requested funds with your second account. Now isn’t this a delight? It is now possible to request any mosaic from any account and involved accounts are all required to co-sign the transaction.
The pullfunds transactions available in NEM2 will open the doors to innovative business use cases. We are very excited to be part of the NEM experience and very eager to research, use and analyse it. Funds requests are just one type of transactions that are possible with NEM2, read ahead to find out more!
Sending and receiving tokens
We have already seen a more complicated way of transfer in order to fund our accounts. We will now initiate simple transfers and get information about our account balances.
We will create a transfer transaction from our first account to our second account. This transfer transaction will send 1 XEM to our second account and attach a message to it with the content: Welcome to NEM2.
With nem2-cli, this will be just one command to execute. We need to set a recipient, an amount and a message for the transaction, as shows the following command. Please replace ADDRESS_SECOND_ACCOUNT with the address of your freshly created second account.
$ nem2-cli transaction transfer –recipient ADDRESS_SECOND_ACCOUNT –message “Welcome to NEM2.” –mosaics nem:xem::1000000
Mark the 1’000’000 amount, which represents the amount we want to send, expressed in the smallest unit of the XEM mosaic. XEM amounts have a divisibility of 6, which means we need to add six zeros if we want to send 1 XEM.
In our earlier example, we requested a fund transfer with an amount of 5’000’000, the same principle was applied there. Since we were requesting XEM, we added six zeros in order to request 5 XEM, and not just 0.000005 XEM.
We have now sent funds to our second account. It is time to monitor this second account, and get information about account balances.
Monitor NEM2 Accounts
Now that we have sent out our first transfer transaction to our second account, it is time to monitor the account and check for incoming transactions.
Yet again, nem2-cli is perfect for this task. Following command can be used to monitor transactions of a said account on the NEM2 network:
$ nem2-cli monitor confirmed –address ADDRESS_SECOND_ACCOUNT
Once the transaction has been confirmed, the state of our account will be updated. This means that we will have an increased balance of XEM for our second account.
Let us verify this with the NEM2 API, execute the following command to view your account information:
$ nem2-cli account info –address ADDRESS_SECOND_ACCOUNT
You should get something like the following illustration:
Example of an Account Info result with a nem:xem balance.
There is more than the info command to discover in the nem2-cli account module. Following are valid commands which you can execute to see some information about your account state:
$ nem2-cli account info –address ADDRESS
$ nem2-cli account transactions –publickey PUBLIC_KEY
$ nem2-cli account incoming –publickey PUBLIC_KEY
$ nem2-cli account outgoing –publickey PUBLIC_KEY
$ nem2-cli account aggregatebonded –publickey PUBLIC_KEY
$ nem2-cli account unconfirmed –publickey PUBLIC_KEY
If you didn’t note down your public key, you can always jump back to the nem2-cli profile listcommand which will give you an overview of all your stored keys.
With these commands, you can monitor the state of an account very easily. Have a look at the nem2-cli and nem2-sdk source code packages to get more details about the NEM2 APIs.
What else should you know about NEM2?
NEM2 is an advanced blockchain system for which the architecture and source code have been started from scratch and come with the latest innovations of the blockchain field.
Advanced capabilities for the NEM2 blockchain include but are not limited to:
Atomic swaps of tokens
Multi-level multi-signature accounts
Smart asset system
Aggregate Transactions
Before it gets too complicated, let us research each of these innovations and define how they can be used or integrated in your business logic.
Atomic token swaps
Blockchains and cryptocurrencies have not only opened the doors to a faster transfer of value. With blockchain platforms like NEM2, it is now possible to execute contracts holding value, in a distributed fashion. And more over, those contracts can be atomic.
We are not talking about atoms, but about the atomicity of transactions. From a quick research on what atomic transactions should be we can find:
An atomic transaction is an indivisible and irreducible series of database operations such that either all occur, or nothing occurs
Replace database operations with account transactions in that quote. Atomic token swapsperform multiple transactions with the condition that either all execute or none.
This is very useful in many cases, for instance in the case of transfer of value between two different blockchain networks (token swap). So-called cross-chain token swaps are possible with the current NEM2 technology and we’ll let you know how to implement those in upcoming articles!
Another useful example – outside of the cryptocurrency domain – would be to use a blockchain to facilitate and manage the access to an automated office with many sister companies. A private blockchain would be used as to manage sensitive data privately but sister companies would all share one common distributed ledger as their access database.
It is probable that some of those use cases will require the issuance of multiple cryptocurrencies, in order to represent different components of their business logic. We can see today that digitalisation has to happen on many fronts.
In our automated office use case, atomic swaps will be the communication layer between inter-connected devices (IoT) to exchange value and execute digitalised contracts holding value on different platforms.
Multi-level Multi-signature
Multi-signature transactions in NEM2 combine simplicity and power. You can define a whole hierarchy of co-signer for your multi-signature accounts.
As an example of a multi-level multi-signature account we can define a Distributed Decision Tree in a software company for an upcoming release. Each of the involved accounts are NEM2 accounts as we created earlier. Let us take the following schema as an example:
Each department has its own multi-signature account, for which employees are co-signers.
In this case, the multi-signature configuration is straight-forward. The multi-signature account at the top of the hierarchy is a 3 of 3 multi-signature account which means that all three – the Marketing Team, the Finance Team and the Developer Team – must confirm the release with their respective minimum number of co-signatures.
For instance if two people of the Developer team define the release as being unsafe, they would not co-sign the release announcement transaction. This would block the announcement from happening. With such a structure, many digitalised companies may be managed remotely. Organisations, offices, companies, houses, facilities, etc. – as well.
Many things of our daily lives have yet to discover their digital counterparts.
Smart assets system
What exactly are smart assets? Is this just a marketing buzz created around the word smart?Well, as you will see, with NEM2, assets are indeed smart. They are configurable with properties like mutability of the supply, divisibility (or number of decimals) and dynamic fees (so-called levy fee).
NEM2 comes with an improved Namespace and Mosaics module. Mosaics on NEM are custom tokens created on the public network. On NEM2, it is possible to issue your own Mosaic as well. With many other features than just name registrations, Namespaces and Mosaics are very similar to working with your own blockchain.
NEM2 gives you all the API endpoints needed to manage your custom token without the hassle of re-defining your entire business logic.
As it was already the case with the previous version of NEM (NIS1), NEM2 comes with feature sets laid around powerful aggregate transactions which basically let you create any type of business flows – also with your custom tokens – and make them atomic or co-owned.
Aggregate Transactions
The simplest definition for aggregate transactions would be that they are transaction wrappers which can hold up to 1000 inner transactions also involving up to 15 different accounts.
This system is now also used to allow multi-signature pushes. In fact, using NEM2, you can create aggregate bonded transactions, which are [multiple or one] transaction(s) waiting for co-signatures.
In this way, in NEM2, Multi-signature has been improved to not only be account specific. As, for instance, an aggregate bonded transaction which contains two transfers from two different accounts. The transaction requires the two accounts to co-sign the aggregate bonded.
The inner transactions will all be executed at the same time only if all necessary co-signatures are pushed. Again, potential use cases for this are not defined, but you can have a quick overview of the possibilities on the nem.io website.
In this article we already used an aggregate transaction. When we requested funds manually, we actually created more than one transaction. In total, we created three transactions, two of which are wrapped in an aggregate transaction as listed below:
We created a Hash Lock transaction with 10 XEM inside. This is required by the NEM2 network to prevent spamming.
We created an Aggregate Bonded transaction with 5 XEM inside.
A first inner transaction holding a message to ask for funds
A second inner transaction holding the funds we requested
The advantage with aggregate transactions is that their inner transactions are executed all at once. Multiple actors are involved and operate the aggregate bonded transaction, each of them being notified for their needed actions.
A very powerful feature with aggregate transactions would be the example of a cross chain token swap as demonstrated on the nemtech github pages.
For the early NEMbers who created Mosaics before. Imagine creating your Mosaic and paying XEM fees for your shareholders so that they don’t need to buy XEM to work with your Mosaic. It is actually very simple with aggregate transactions on NEM2.
Conclusion
The NEM2 software may still be under development but it allows for any innovative ideas to be implemented around a standards complying blockchain protocol that is actively being improved.
Building with NEM2 is kept simple, and adapts very well to your business logic, without requiring business logic changes for the integration.
NEM2 comes with qualitative peer reviewed source code and a well-thought-of architecture layer making the work with NEM2 a delight.
Have a look at the available NEM2 repositories on Github:
nemtech: The NEM2 Github Organisation
catapult-server: The Peer-to-Peer reference implementation.
catapult-rest: The RESTful API reference implementation.
nem2-docs: The documentation package.
community: How to work with the Open Source NEM2 community.
There is a lot more of course, but those are the repositories which are being worked on more actively at the time of writing this article.
A complete history of terminal commands for this article can be found on Github. We sincerely hope you enjoyed this article and would love to read your feedback! Feel free to contact us via our website or social media platforms.
NEM2 will revolutionise the way you interact with blockchain!
And don’t forget to #NEMJoy!