Skip to content

Commit 8a94f09

Browse files
committed
chore: improve midnight docs
1 parent 043d161 commit 8a94f09

7 files changed

Lines changed: 762 additions & 235 deletions

File tree

blockfrost-openapi.yaml

Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,14 @@ info:
329329
330330
### Authentication
331331
332-
Include your project ID as the `project_id` HTTP header.
332+
Include your project ID as the `project_id` HTTP header:
333+
334+
```bash
335+
curl -X POST https://midnight-mainnet.blockfrost.io/api/v0 \
336+
-H "project_id: YOUR_PROJECT_ID" \
337+
-H "Content-Type: application/json" \
338+
-d '{"query": "{ block { hash height } }"}'
339+
```
333340
334341
Alternatively, you can use **HTTP Basic Auth** directly in the endpoint URL. The username is the network prefix and the password is your project ID:
335342
@@ -374,13 +381,31 @@ info:
374381
curl -X POST https://midnight-mainnet.blockfrost.io/api/v0 \
375382
-H "project_id: YOUR_PROJECT_ID" \
376383
-H "Content-Type: application/json" \
377-
-d '{"query": "{ transactions(offset: { hash: \"YOUR_TX_HASH\" }) { hash protocolVersion block { height hash } } }"}'
384+
-d '{"query": "{ transactions(offset: { hash: \"YOUR_TX_HASH\" }) { hash protocolVersion fees { paidFees estimatedFees } block { height hash } } }"}'
385+
```
386+
387+
**Query DUST generation status:**
388+
```bash
389+
curl -X POST https://midnight-mainnet.blockfrost.io/api/v0 \
390+
-H "project_id: YOUR_PROJECT_ID" \
391+
-H "Content-Type: application/json" \
392+
-d '{"query": "{ dustGenerationStatus(cardanoRewardAddresses: [\"YOUR_CARDANO_REWARD_ADDRESS\"]) { cardanoRewardAddress dustAddress registered nightBalance generationRate currentCapacity } }"}'
393+
```
394+
395+
**Query contract actions:**
396+
```bash
397+
curl -X POST https://midnight-mainnet.blockfrost.io/api/v0 \
398+
-H "project_id: YOUR_PROJECT_ID" \
399+
-H "Content-Type: application/json" \
400+
-d '{"query": "{ contractAction(address: \"YOUR_CONTRACT_ADDRESS\") { address state transaction { hash } unshieldedBalances { tokenType amount } } }"}'
378401
```
379402
380403
### WebSocket Subscriptions
381404
382405
Subscriptions use a WebSocket connection following the GraphQL over WebSocket protocol.
383406
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.
408+
384409
**Connecting with `websocat`:**
385410
```bash
386411
websocat wss://midnight-mainnet.blockfrost.io/api/v0/ws \
@@ -495,13 +520,72 @@ info:
495520
496521
If no offset is provided, the latest result is returned.
497522
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 \
534+
-H "project_id: YOUR_PROJECT_ID" \
535+
-H "Content-Type: application/json" \
536+
-d '{"query": "mutation { connect(viewingKey: \"YOUR_VIEWING_KEY\") }"}'
537+
```
538+
539+
Response:
540+
```json
541+
{
542+
"data": {
543+
"connect": "SESSION_ID_HEX"
544+
}
545+
}
546+
```
547+
548+
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 \
571+
-H "project_id: YOUR_PROJECT_ID" \
572+
-H "Content-Type: application/json" \
573+
-d '{"query": "mutation { disconnect(sessionId: \"SESSION_ID_HEX\") }"}'
574+
```
575+
498576
### Available Operations
499577
500578
The following links will redirect you to the Midnight GraphQL API Reference:
501579
502-
* [**Queries**](midnight/#group-Operations-Queries): Fetch blockchain data (blocks, transactions, contracts, DUST status, governance parameters)
503-
* [**Mutations**](midnight/#group-Operations-Mutations): Wallet connection management (connect/disconnect)
504-
* [**Subscriptions**](midnight/#group-Operations-Subscriptions): Real-time updates via WebSocket (blocks, contract actions, transactions, ledger events)
580+
* [**Queries**](midnight/#group-Operations-Queries): Fetch blockchain data (blocks, transactions, contracts, DUST generation status)
581+
* [**Mutations**](midnight/#group-Operations-Mutations): Wallet session management (`connect`/`disconnect`)
582+
* [**Subscriptions**](midnight/#group-Operations-Subscriptions): Real-time updates via WebSocket:
583+
* `blocks` — new blocks
584+
* `contractActions` — contract events for a specific address
585+
* `shieldedTransactions` — shielded transaction events for a wallet session (requires `connect`)
586+
* `unshieldedTransactions` — unshielded transaction events for an address
587+
* `dustLedgerEvents` — DUST ledger state changes
588+
* `zswapLedgerEvents` — zswap ledger state changes
505589
506590
507591
For the full list of available queries, mutations, subscriptions and types, see

docs/blockfrost-openapi.yaml

Lines changed: 137 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,16 @@ info:
456456
### Authentication
457457
458458
459-
Include your project ID as the `project_id` HTTP header.
459+
Include your project ID as the `project_id` HTTP header:
460+
461+
462+
```bash
463+
464+
curl -X POST https://midnight-mainnet.blockfrost.io/api/v0 \
465+
-H "project_id: YOUR_PROJECT_ID" \
466+
-H "Content-Type: application/json" \
467+
-d '{"query": "{ block { hash height } }"}'
468+
```
460469
461470
462471
Alternatively, you can use **HTTP Basic Auth** directly in the endpoint URL.
@@ -526,7 +535,29 @@ info:
526535
curl -X POST https://midnight-mainnet.blockfrost.io/api/v0 \
527536
-H "project_id: YOUR_PROJECT_ID" \
528537
-H "Content-Type: application/json" \
529-
-d '{"query": "{ transactions(offset: { hash: \"YOUR_TX_HASH\" }) { hash protocolVersion block { height hash } } }"}'
538+
-d '{"query": "{ transactions(offset: { hash: \"YOUR_TX_HASH\" }) { hash protocolVersion fees { paidFees estimatedFees } block { height hash } } }"}'
539+
```
540+
541+
542+
**Query DUST generation status:**
543+
544+
```bash
545+
546+
curl -X POST https://midnight-mainnet.blockfrost.io/api/v0 \
547+
-H "project_id: YOUR_PROJECT_ID" \
548+
-H "Content-Type: application/json" \
549+
-d '{"query": "{ dustGenerationStatus(cardanoRewardAddresses: [\"YOUR_CARDANO_REWARD_ADDRESS\"]) { cardanoRewardAddress dustAddress registered nightBalance generationRate currentCapacity } }"}'
550+
```
551+
552+
553+
**Query contract actions:**
554+
555+
```bash
556+
557+
curl -X POST https://midnight-mainnet.blockfrost.io/api/v0 \
558+
-H "project_id: YOUR_PROJECT_ID" \
559+
-H "Content-Type: application/json" \
560+
-d '{"query": "{ contractAction(address: \"YOUR_CONTRACT_ADDRESS\") { address state transaction { hash } unshieldedBalances { tokenType amount } } }"}'
530561
```
531562
532563
@@ -537,6 +568,12 @@ info:
537568
WebSocket protocol.
538569
539570
571+
Most subscriptions accept an optional `offset` parameter, allowing you to
572+
resume from a specific block height or transaction hash instead of starting
573+
from the tip. This is useful for catching up after a reconnect without
574+
re-processing events you've already seen.
575+
576+
540577
**Connecting with `websocat`:**
541578
542579
```bash
@@ -701,21 +738,113 @@ info:
701738
702739
If no offset is provided, the latest result is returned.
703740
741+
742+
### Shielded Transactions
743+
744+
745+
Shielded transactions are at the core of Midnight's privacy model. Because
746+
transaction data is encrypted on-chain, the indexer needs a **viewing key**
747+
to determine which transactions are relevant to a specific wallet.
748+
749+
750+
The `connect` mutation establishes a server-side session for a given viewing
751+
key. The indexer uses this key to scan the chain and filter shielded
752+
transactions relevant to that wallet. It returns a **session ID** used to
753+
authenticate the `shieldedTransactions` subscription.
754+
755+
756+
When you no longer need to monitor shielded transactions for a wallet, call
757+
the `disconnect` mutation with the session ID to end the session and free
758+
server-side resources.
759+
760+
761+
**Step 1 — Connect with a viewing key:**
762+
763+
```bash
764+
765+
curl -X POST https://midnight-mainnet.blockfrost.io/api/v0 \
766+
-H "project_id: YOUR_PROJECT_ID" \
767+
-H "Content-Type: application/json" \
768+
-d '{"query": "mutation { connect(viewingKey: \"YOUR_VIEWING_KEY\") }"}'
769+
```
770+
771+
772+
Response:
773+
774+
```json
775+
776+
{
777+
"data": {
778+
"connect": "SESSION_ID_HEX"
779+
}
780+
}
781+
782+
```
783+
784+
785+
The viewing key can be in Bech32m format (preferred, e.g.
786+
`mn_shield-esk1...`) or hex.
787+
788+
789+
**Step 2 — Subscribe to shielded transactions:**
790+
791+
792+
Using the session ID from the `connect` mutation, subscribe via WebSocket:
793+
794+
```json
795+
796+
{
797+
"id": "1",
798+
"type": "subscribe",
799+
"payload": {
800+
"query": "subscription($sid: HexEncoded!) { shieldedTransactions(sessionId: $sid, sendProgressUpdates: true) { ... on ViewingUpdate { index update { ... on RelevantTransaction { transaction { hash } } } } ... on ShieldedTransactionsProgress { highestIndex highestRelevantIndex highestRelevantWalletIndex } } }",
801+
"variables": { "sid": "SESSION_ID_HEX" }
802+
}
803+
}
804+
805+
```
806+
807+
808+
The subscription emits two event types:
809+
810+
* `ViewingUpdate` — contains relevant transactions and Merkle tree updates
811+
for the wallet
812+
813+
* `ShieldedTransactionsProgress` — reports sync progress (`highestIndex`,
814+
`highestRelevantIndex`, `highestRelevantWalletIndex`), useful for showing
815+
progress in a UI. Controlled by the `sendProgressUpdates` parameter
816+
(default: `true`).
817+
818+
819+
**Step 3 — Disconnect when done:**
820+
821+
```bash
822+
823+
curl -X POST https://midnight-mainnet.blockfrost.io/api/v0 \
824+
-H "project_id: YOUR_PROJECT_ID" \
825+
-H "Content-Type: application/json" \
826+
-d '{"query": "mutation { disconnect(sessionId: \"SESSION_ID_HEX\") }"}'
827+
```
828+
704829
### Available Operations
705830
706831
The following links will redirect you to the Midnight GraphQL API Reference:
707832
708833
709834
* [**Queries**](midnight/#group-Operations-Queries): Fetch blockchain data
710-
(blocks, transactions, contracts, DUST status, governance parameters)
835+
(blocks, transactions, contracts, DUST generation status)
711836
712-
* [**Mutations**](midnight/#group-Operations-Mutations): Wallet connection
713-
management (connect/disconnect)
837+
* [**Mutations**](midnight/#group-Operations-Mutations): Wallet session
838+
management (`connect`/`disconnect`)
714839
715840
* [**Subscriptions**](midnight/#group-Operations-Subscriptions): Real-time
716-
updates via WebSocket (blocks, contract actions, transactions, ledger
717-
events)
718-
841+
updates via WebSocket:
842+
* `blocks` — new blocks
843+
* `contractActions` — contract events for a specific address
844+
* `shieldedTransactions` — shielded transaction events for a wallet session (requires `connect`)
845+
* `unshieldedTransactions` — unshielded transaction events for an address
846+
* `dustLedgerEvents` — DUST ledger state changes
847+
* `zswapLedgerEvents` — zswap ledger state changes
719848
720849
721850
For the full list of available queries, mutations, subscriptions and types,

0 commit comments

Comments
 (0)