You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Subscriptions use a WebSocket connection following the GraphQL over WebSocket protocol.
383
406
407
+
Most subscriptions accept an optional `offset` parameter, allowing you to resume from a specific block height or transaction hash instead of starting from the tip. This is useful for catching up after a reconnect without re-processing events you've already seen.
If no offset is provided, the latest result is returned.
497
522
523
+
### Shielded Transactions
524
+
525
+
Shielded transactions are at the core of Midnight's privacy model. Because transaction data is encrypted on-chain, the indexer needs a **viewing key** to determine which transactions are relevant to a specific wallet.
526
+
527
+
The `connect` mutation establishes a server-side session for a given viewing key. The indexer uses this key to scan the chain and filter shielded transactions relevant to that wallet. It returns a **session ID** used to authenticate the `shieldedTransactions` subscription.
528
+
529
+
When you no longer need to monitor shielded transactions for a wallet, call the `disconnect` mutation with the session ID to end the session and free server-side resources.
530
+
531
+
**Step 1 — Connect with a viewing key:**
532
+
```bash
533
+
curl -X POST https://midnight-mainnet.blockfrost.io/api/v0 \
The viewing key can be in Bech32m format (preferred, e.g. `mn_shield-esk1...`) or hex.
549
+
550
+
**Step 2 — Subscribe to shielded transactions:**
551
+
552
+
Using the session ID from the `connect` mutation, subscribe via WebSocket:
553
+
```json
554
+
{
555
+
"id": "1",
556
+
"type": "subscribe",
557
+
"payload": {
558
+
"query": "subscription($sid: HexEncoded!) { shieldedTransactions(sessionId: $sid, sendProgressUpdates: true) { ... on ViewingUpdate { index update { ... on RelevantTransaction { transaction { hash } } } } ... on ShieldedTransactionsProgress { highestIndex highestRelevantIndex highestRelevantWalletIndex } } }",
559
+
"variables": { "sid": "SESSION_ID_HEX" }
560
+
}
561
+
}
562
+
```
563
+
564
+
The subscription emits two event types:
565
+
* `ViewingUpdate` — contains relevant transactions and Merkle tree updates for the wallet
566
+
* `ShieldedTransactionsProgress` — reports sync progress (`highestIndex`, `highestRelevantIndex`, `highestRelevantWalletIndex`), useful for showing progress in a UI. Controlled by the `sendProgressUpdates` parameter (default: `true`).
567
+
568
+
**Step 3 — Disconnect when done:**
569
+
```bash
570
+
curl -X POST https://midnight-mainnet.blockfrost.io/api/v0 \
0 commit comments