# JSON Ledger APIの読み出し

> JSON Ledger APIで台帳を読む呼び出しを、読むイベントの絞り込み、createとexerciseのイベント、activeなコントラクト、updateのstream、WebSocketまで、章の中の図解で追います。

- URL: https://cardene.dev/diagrams/canton-json-ledger-reading
- 公開日: 2026-11-23
- 更新日: 2026-11-23
- トピック: Blockchain
- タグ: Canton
- 親の図解: [Canton Networkの全体像](https://cardene.dev/diagrams/canton-network.md): トランザクションの中身を関わるpartyにだけ見せるCanton Networkについて、部品ごとの役割と、1つのトランザクションが部品の間をどう流れるかを段ごとに追います。
- 子の図解: [JSONで読むイベントを絞り込む](https://cardene.dev/diagrams/canton-json-event-filters.md): JSON Ledger APIで読むイベントを、partyとtemplateとinterfaceとトランザクションの形でどう絞り込み、返す値をどう描かせるかを、リクエストの本文の欄の入れ子で追います。
- 子の図解: [作られたコントラクトのイベントを読む](https://cardene.dev/diagrams/canton-json-created-events.md): JSON Ledger APIが返すcreateのイベントの欄と、見えるpartyと、常にhostされるとは限らないpartyの読み方と、後のコマンドで使う開示用のデータとinterfaceのviewを追います。
- 子の図解: [トランザクションとexerciseを読む](https://cardene.dev/diagrams/canton-json-transaction-events.md): JSON Ledger APIが返すトランザクションとarchiveとexerciseのイベントの欄と、見えるpartyと、exerciseの子孫のイベントを木に組み直す手がかりを追います。
- 子の図解: [activeなコントラクトを問い合わせる](https://cardene.dev/diagrams/canton-json-active-contracts.md): JSON Ledger APIで、あるoffsetのactiveなコントラクトを、1回の呼び出しで一覧として受け取る方法と、頁ごとに受け取る方法と、1つのコントラクトをIDで取得する方法を追います。
- 子の図解: [途中のreassignmentを読み解く](https://cardene.dev/diagrams/canton-json-incomplete-reassignments.md): activeなコントラクトの問い合わせで、assignedイベントだけかunassignedイベントだけが確認できる形の欄と、unassignのIDで対のイベントを突き合わせる形を追います。
- 子の図解: [updateを順に読み進める](https://cardene.dev/diagrams/canton-json-update-stream.md): JSON Ledger APIで台帳のupdateを配列と頁で読み進める呼び出しと、updateをIDかoffsetで1件取得する呼び出しと、断られる所を追います。
- 子の図解: [WebSocketでstreamを読む](https://cardene.dev/diagrams/canton-json-websocket.md): JSON Ledger APIのWebSocketで、completionとactiveなコントラクトとupdateのストリームを、チャンネルごとにどう要求し、何を受け取るかを追います。
- 子の図解: [updateで移動とtrafficを追う](https://cardene.dev/diagrams/canton-json-reassign-traffic.md): updateのreassignmentとtopology transactionが持つ欄と、trafficの費用が入らない場合と、アカウントの残高を更新するエンドポイントを追います。

前の章「JSON Ledger APIのコマンドの送信」では、JSON Ledger APIでコマンドを送り、結果と完了を受け取るまでを追いました。
この章では、JSON Ledger APIで台帳から読む側を追います。
gRPCのLedger APIで同じことを書いたのは、章「台帳の読み出し」なので、仕組みはその章の頁を指し、この章はJSONの呼び方と欄の形を書きます。

:::details gRPC
gRPCは、Googleが開発した、ネットワーク越しに別のプログラムの処理を呼び出すための通信の仕組みです。
:::

:::details JSON
JSONは、データを文字で表すための形式で、Webのプログラムどうしのデータのやり取りに広く使われています。
:::

https://cardene.dev/diagrams/canton-ledger-reading

まず、読むイベントを絞り込む指定を見ます。
partyとtemplateとinterfaceの絞り込み、トランザクションの形の指定、updateの種類ごとの指定を追います。

https://cardene.dev/diagrams/canton-json-event-filters

次に、作られたコントラクトのイベントを見ます。
createのイベントが持つ欄と、見えるpartyと、後のコマンドで使う形を追います。

https://cardene.dev/diagrams/canton-json-created-events

続いて、トランザクションとarchiveとexerciseのイベントを見ます。
トランザクションの欄と、イベントの見えるpartyと、exerciseのイベントを木に組み直す形を追います。

https://cardene.dev/diagrams/canton-json-transaction-events

そのあと、あるoffsetでactiveなコントラクトを問い合わせる呼び出しを見ます。
1回の呼び出しと頁ごとの呼び出しで受け取る方法と、1つのコントラクトをIDで取得する方法を追います。

offsetは、streamの中の位置を表す値です。

https://cardene.dev/diagrams/canton-json-active-contracts

さらに、activeなコントラクトの問い合わせに混じる、途中のreassignmentを見ます。
assignのイベントだけかunassignのイベントだけが確認できる形の持つ物と、unassignのIDでの突き合わせ方を追います。

reassignmentは、移す元のSynchronizerでunassignし、移す先のSynchronizerでassignする2段の手順です。

https://cardene.dev/diagrams/canton-json-incomplete-reassignments

その次に、updateを順に読み進める呼び出しを見ます。
配列と頁で読む形と、updateを1件取得する形と、断られる所を追います。

https://cardene.dev/diagrams/canton-json-update-stream

また、WebSocketでストリームを読む呼び出しを見ます。
completionとactiveなコントラクトとupdateのストリームを、どう要求し、何を受け取るかを追います。

WebSocketは、1つの接続の上で、サーバーとクライアントが続けてデータを送り合える通信の仕組みです。

https://cardene.dev/diagrams/canton-json-websocket

最後に、updateでコントラクトの移動と権限の変化とtrafficの費用を読む呼び出しを見ます。
続けて、別の呼び出しでtrafficのアカウントの残高を更新する形を追います。

https://cardene.dev/diagrams/canton-json-reassign-traffic

図に出るイベントや欄の語は、箱が指す頁が説明します。

下の図は、この章の8つの頁が扱う物を、アプリとParticipant Nodeから、HTTPのPOSTとWebSocketのストリーム、コントラクトの取得とupdateを読む呼び出し、その中の物の順に置きます。
HTTPの呼び出しは、POSTの版だけを描きます。
activeなコントラクトを頁ごとに受け取る呼び出しの同じパスのGETの版は、版3.5で非推奨になり、頁「activeなコントラクトを問い合わせる」が書きます。

HTTPは、ブラウザやプログラムがWebのサーバーと要求と応答をやり取りする決まりです。

虫眼鏡の印が付いた部品を押すと、その部品の中へ入ります。
外側へ戻る時は、右上の「戻る」か、上に並んだ名前を押します。
図の上の全体の木で部品を押すと、その部品の中へ直接移れます。

部品の中へ入ると、名前の並びの下にその部品を説明する頁の題が出て、押すとその頁を開きます。
中を持たない部品には、箱の下に頁の題が出ます。

```dragon
architecture アプリからJSON Ledger APIへ
group Top as 台帳を読む所 [icon: net]
  box App as アプリ [note: 台帳を読む要求を送る, color: blue, icon: app, link: /diagrams/canton-json-event-filters]
  box Node as Participant Node [note: JSON Ledger APIを出す, color: slate, icon: server, link: /diagrams/canton-json-active-contracts]
end
group NodeIn as Participant Nodeの中 [color: slate, icon: server]
  box Http as HTTPのPOST [note: 台帳を読む呼び出し, icon: refresh, link: /diagrams/canton-json-update-stream]
  box Ws as WebSocketのストリーム [note: completionとactiveなコントラクトとupdate, icon: refresh, link: /diagrams/canton-json-websocket]
end
group HttpIn as HTTPのPOSTの中 [color: slate, icon: refresh]
  box Act as コントラクトの取得 [note: activeなコントラクトをoffsetで一覧する。IDでの取得は別の呼び出し, link: /diagrams/canton-json-active-contracts]
  box Upd as updateを読む呼び出し [note: 配列と頁と1件で読む, icon: refresh, link: /diagrams/canton-json-update-stream]
end
group ActIn as コントラクトの取得の中 [color: slate, icon: db]
  box Cre as 有効なコントラクト [note: 応答に含まれ、createのイベントを持つ, icon: card, link: /diagrams/canton-json-created-events]
  box Inc as 途中のreassignment [note: 指定したoffsetまでに、片側のイベントだけを観測した形, icon: refresh, link: /diagrams/canton-json-incomplete-reassignments]
end
group UpdIn as updateを読む呼び出しの中 [color: slate, icon: refresh]
  box Tx as トランザクション [note: 指定した形でイベントが変わる, link: /diagrams/canton-json-transaction-events]
  box Rt as 移動とtraffic [note: reassignmentとtopology transactionの欄。trafficの費用は条件により入る, icon: card, link: /diagrams/canton-json-reassign-traffic]
end

step アプリからJSON Ledger APIへ
  say アプリは、台帳を読む要求を、JSON Ledger APIを出すParticipant Nodeへ送ります。イベントを指定して読む要求には、読むイベントの絞り込みを入れます。
  App -> Node: 要求を送る
  source CantonのPOST /v2/state/active-contracts-page [url: https://docs.canton.network/reference/json-api-reference/post-v2stateactive-contracts-page]
  source CantonのGET /v2/state/active-contracts-page [url: https://docs.canton.network/reference/json-api-reference/get-v2stateactive-contracts-page]
  source CantonのPOST /v2/state/active-contracts [url: https://docs.canton.network/reference/json-api-reference/post-v2stateactive-contracts]
  source CantonのPOST /v2/updates [url: https://docs.canton.network/reference/json-api-reference/post-v2updates]
  source CantonのPOST /v2/commands/submit-and-wait-for-reassignment [url: https://docs.canton.network/reference/json-api-reference/post-v2commandssubmit-and-wait-for-reassignment]
  source CantonのPOST /v2/commands/submit-and-wait-for-transaction [url: https://docs.canton.network/reference/json-api-reference/post-v2commandssubmit-and-wait-for-transaction]
  source CantonのPOST /v2/contracts/contract-by-id [url: https://docs.canton.network/reference/json-api-reference/post-v2contractscontract-by-id]
  source CantonのPOST /v2/events/events-by-contract-id [url: https://docs.canton.network/reference/json-api-reference/post-v2eventsevents-by-contract-id]

step Participant Nodeの中
  say Participant Nodeの中では、JSON Ledger APIが、HTTPのPOSTで台帳を読む呼び出しと、WebSocketでcompletionとactiveなコントラクトとupdateのストリームを読む呼び出しを持ちます。
  act Http: HTTPのPOSTで読む
  act Ws: ストリームで読む
  source CantonのPOST /v2/updates [url: https://docs.canton.network/reference/json-api-reference/post-v2updates]
  source CantonのPOST /v2/updates/get-updates-page [url: https://docs.canton.network/reference/json-api-reference/post-v2updatesget-updates-page]
  source CantonのPOST /v2/updates/update-by-id [url: https://docs.canton.network/reference/json-api-reference/post-v2updatesupdate-by-id]
  source CantonのPOST /v2/updates/update-by-offset [url: https://docs.canton.network/reference/json-api-reference/post-v2updatesupdate-by-offset]
  source CantonのError Code Reference [url: https://docs.canton.network/global-synchronizer/reference/error-codes]
  source CantonのJSON Ledger APIのAsyncAPI参照 [url: https://docs.canton.network/reference/json-api-asyncapi-reference]
  source CantonのAsyncAPI参照のcommand-completionsのチャンネル [url: https://docs.canton.network/reference/json-api-asyncapi-reference/channels/v2-commands-command-completions]
  source CantonのAsyncAPI参照のactive-contractsのチャンネル [url: https://docs.canton.network/reference/json-api-asyncapi-reference/channels/v2-state-active-contracts]
  source CantonのAsyncAPI参照のupdatesのチャンネル [url: https://docs.canton.network/reference/json-api-asyncapi-reference/channels/v2-updates]
  source CantonのAsyncAPI参照のcommand-completionsのpublish [url: https://docs.canton.network/reference/json-api-asyncapi-reference/operations/v2-commands-command-completions/publish]
  source CantonのAsyncAPI参照のcommand-completionsのsubscribe [url: https://docs.canton.network/reference/json-api-asyncapi-reference/operations/v2-commands-command-completions/subscribe]
  source CantonのAsyncAPI参照のactive-contractsのpublish [url: https://docs.canton.network/reference/json-api-asyncapi-reference/operations/v2-state-active-contracts/publish]
  source CantonのAsyncAPI参照のactive-contractsのsubscribe [url: https://docs.canton.network/reference/json-api-asyncapi-reference/operations/v2-state-active-contracts/subscribe]
  source CantonのAsyncAPI参照のupdatesのpublish [url: https://docs.canton.network/reference/json-api-asyncapi-reference/operations/v2-updates/publish]
  source CantonのAsyncAPI参照のupdatesのsubscribe [url: https://docs.canton.network/reference/json-api-asyncapi-reference/operations/v2-updates/subscribe]
  source CantonのJSON Ledger API [url: https://docs.canton.network/sdks-tools/api-reference/json-api]
  source CantonのPOST /v2/commands/command-completions [url: https://docs.canton.network/reference/json-api-reference/post-v2commandscommand-completions]
  source CantonのPOST /v2/state/active-contracts [url: https://docs.canton.network/reference/json-api-reference/post-v2stateactive-contracts]

step HTTPのPOSTの中
  say HTTPのPOSTには、コントラクトの取得と、updateを配列と頁と1件で読む呼び出しがあります。activeなコントラクトの頁は、offsetでの一覧と、IDでの取得を、別の呼び出しとして書きます。
  act Act: activeなコントラクトを問い合わせる
  act Upd: updateを読む
  source CantonのPOST /v2/state/active-contracts-page [url: https://docs.canton.network/reference/json-api-reference/post-v2stateactive-contracts-page]
  source CantonのGET /v2/state/active-contracts-page [url: https://docs.canton.network/reference/json-api-reference/get-v2stateactive-contracts-page]
  source CantonのPOST /v2/state/active-contracts [url: https://docs.canton.network/reference/json-api-reference/post-v2stateactive-contracts]
  source CantonのPOST /v2/contracts/contract-by-id [url: https://docs.canton.network/reference/json-api-reference/post-v2contractscontract-by-id]
  source CantonのPOST /v2/events/events-by-contract-id [url: https://docs.canton.network/reference/json-api-reference/post-v2eventsevents-by-contract-id]
  source CantonのPOST /v2/updates [url: https://docs.canton.network/reference/json-api-reference/post-v2updates]
  source CantonのPOST /v2/updates/get-updates-page [url: https://docs.canton.network/reference/json-api-reference/post-v2updatesget-updates-page]
  source CantonのPOST /v2/updates/update-by-id [url: https://docs.canton.network/reference/json-api-reference/post-v2updatesupdate-by-id]
  source CantonのPOST /v2/updates/update-by-offset [url: https://docs.canton.network/reference/json-api-reference/post-v2updatesupdate-by-offset]
  source CantonのError Code Reference [url: https://docs.canton.network/global-synchronizer/reference/error-codes]

step コントラクトの取得の中
  say activeなコントラクトの問い合わせの応答には、createのイベントを持つ有効なコントラクトと、途中のreassignmentが入ります。途中のreassignmentは、指定したoffsetまでに移動の片側だけを観測した形で、unassign側にはcreateのイベントの欄もあります。
  act Cre: createのイベントを持つ
  act Inc: 片側のイベントだけ
  source CantonのGET /v2/state/active-contracts-page [url: https://docs.canton.network/reference/json-api-reference/get-v2stateactive-contracts-page]
  source CantonのPOST /v2/state/active-contracts-page [url: https://docs.canton.network/reference/json-api-reference/post-v2stateactive-contracts-page]
  source CantonのPOST /v2/state/active-contracts [url: https://docs.canton.network/reference/json-api-reference/post-v2stateactive-contracts]
  source CantonのPOST /v2/updates [url: https://docs.canton.network/reference/json-api-reference/post-v2updates]
  source CantonのPOST /v2/commands/submit-and-wait-for-reassignment [url: https://docs.canton.network/reference/json-api-reference/post-v2commandssubmit-and-wait-for-reassignment]
  source CantonのPOST /v2/commands/submit-and-wait-for-transaction [url: https://docs.canton.network/reference/json-api-reference/post-v2commandssubmit-and-wait-for-transaction]

step updateを読む呼び出しの中
  say updateは、指定した形でイベントが変わるトランザクションを返します。ACS deltaの形はcreateとarchive、ledger effectsの形はcreateとexerciseのイベントを持ちます。reassignmentとtopology transactionの欄も返し、トランザクションとreassignmentには、条件によりtrafficの費用の欄も入ります。範囲を読む呼び出しの応答には、読み出しを再開できるoffsetの印も混じります。
  act Tx: トランザクションのイベント
  act Rt: 移動と費用の欄
  source CantonのPOST /v2/updates [url: https://docs.canton.network/reference/json-api-reference/post-v2updates]
  source CantonのPOST /v2/commands/submit-and-wait-for-transaction [url: https://docs.canton.network/reference/json-api-reference/post-v2commandssubmit-and-wait-for-transaction]
  source CantonのGET /v2/updates/transaction-tree-by-id/:update-id [url: https://docs.canton.network/reference/json-api-reference/get-v2updatestransaction-tree-by-id:update-id]
  source CantonのPOST /v2/traffic/accounts [url: https://docs.canton.network/reference/json-api-reference/post-v2trafficaccounts]
```

一番外の階では、アプリからParticipant Nodeへの線が、台帳を読む要求を送る事を表します。
イベントを指定して読む要求に入れる絞り込みは頁「JSONで読むイベントを絞り込む」が追い、activeなコントラクトの問い合わせは頁「activeなコントラクトを問い合わせる」が追います。
どの呼び出しの応答も、Participant Nodeからアプリへ返ります。

Participant Nodeの中では、HTTPのPOSTとWebSocketのストリームを置きます。
HTTPのPOSTでupdateを読む呼び出しは頁「updateを順に読み進める」が、WebSocketの3つのチャンネルは頁「WebSocketでstreamを読む」が追います。

HTTPのPOSTの中では、コントラクトの取得と、updateを読む呼び出しを置きます。
コントラクトの取得の中の有効なコントラクトのcreateのイベントは頁「作られたコントラクトのイベントを読む」が、途中のreassignmentは頁「途中のreassignmentを読み解く」が追います。
updateを読む呼び出しの中のトランザクションのイベントは頁「トランザクションとexerciseを読む」が、reassignmentとtopology transactionの欄と、条件により入るtrafficの費用は頁「updateで移動とtrafficを追う」が追います。

頁ごとにactiveなコントラクトを受け取る時は、全ての頁を取り終えた後で、応答の`activeAtOffset`を、updateを読む要求の`beginExclusive`に使います。
`beginExclusive`は、読む区間の下限で、その値を含みません。
この図は、応答をアプリが次の要求へ渡す向きの線を引きません。

trafficのアカウントの残高を更新する呼び出しは、updateの応答の欄とは別の操作で、図には置かず、頁「updateで移動とtrafficを追う」が追います。

## 出典

https://docs.canton.network/reference/json-api-reference/post-v2stateactive-contracts-page

https://docs.canton.network/reference/json-api-reference/post-v2updates

https://docs.canton.network/reference/json-api-reference/get-v2stateactive-contracts-page

https://docs.canton.network/reference/json-api-reference/post-v2stateactive-contracts

https://docs.canton.network/reference/json-api-reference/post-v2contractscontract-by-id

https://docs.canton.network/reference/json-api-reference/post-v2eventsevents-by-contract-id

https://docs.canton.network/reference/json-api-reference/post-v2commandssubmit-and-wait-for-reassignment

https://docs.canton.network/reference/json-api-reference/post-v2commandssubmit-and-wait-for-transaction

https://docs.canton.network/reference/json-api-reference/get-v2updatestransaction-tree-by-id:update-id

https://docs.canton.network/reference/json-api-reference/post-v2updatesget-updates-page

https://docs.canton.network/reference/json-api-reference/post-v2updatesupdate-by-id

https://docs.canton.network/reference/json-api-reference/post-v2updatesupdate-by-offset

https://docs.canton.network/reference/json-api-reference/post-v2trafficaccounts

https://docs.canton.network/reference/json-api-reference/post-v2commandscommand-completions

https://docs.canton.network/global-synchronizer/reference/error-codes

https://docs.canton.network/reference/json-api-asyncapi-reference

https://docs.canton.network/reference/json-api-asyncapi-reference/channels/v2-commands-command-completions

https://docs.canton.network/reference/json-api-asyncapi-reference/channels/v2-state-active-contracts

https://docs.canton.network/reference/json-api-asyncapi-reference/channels/v2-updates

https://docs.canton.network/reference/json-api-asyncapi-reference/operations/v2-commands-command-completions/publish

https://docs.canton.network/reference/json-api-asyncapi-reference/operations/v2-commands-command-completions/subscribe

https://docs.canton.network/reference/json-api-asyncapi-reference/operations/v2-state-active-contracts/publish

https://docs.canton.network/reference/json-api-asyncapi-reference/operations/v2-state-active-contracts/subscribe

https://docs.canton.network/reference/json-api-asyncapi-reference/operations/v2-updates/publish

https://docs.canton.network/reference/json-api-asyncapi-reference/operations/v2-updates/subscribe

https://docs.canton.network/sdks-tools/api-reference/json-api
