@@ -251,12 +251,25 @@ info:
251251 Create a Midnight project on [blockfrost.io](https://blockfrost.io) and make your first API call:
252252
253253 ```bash
254- curl -X POST https://midnight-{network} .blockfrost.io/api/v0 \
254+ curl -X POST https://midnight-preview .blockfrost.io/api/v0 \
255255 -H "project_id: YOUR_PROJECT_ID" \
256256 -H "Content-Type: application/json" \
257257 -d '{"query": "{ block { hash height timestamp } }"}'
258258 ```
259259
260+ Response:
261+ ```json
262+ {
263+ "data": {
264+ "block": {
265+ "hash": "d193b2686197789ace64962eb3049c5b94c4bbf9b07da04bef034cd75d83afc4",
266+ "height": 192998,
267+ "timestamp": 1770787800000
268+ }
269+ }
270+ }
271+ ```
272+
260273 ### Endpoint
261274
262275 All GraphQL operations (queries, mutations, and subscriptions) use the same endpoint:
@@ -293,8 +306,9 @@ info:
293306 {
294307 "data": {
295308 "block": {
296- "hash": "0x1234...",
297- "height": 100
309+ "hash": "d193b2686197789ace64962eb3049c5b94c4bbf9b07da04bef034cd75d83afc4",
310+ "height": 192998,
311+ "timestamp": 1770787800000
298312 }
299313 }
300314 }
@@ -306,8 +320,8 @@ info:
306320 "data": null,
307321 "errors": [
308322 {
309- "message": "Block not found ",
310- "locations": [{ "line": 1, "column": 1 }],
323+ "message": "Invalid value for argument \"offset.height\" expected type \"Int\" ",
324+ "locations": [{ "line": 1, "column": 15 }],
311325 "path": ["block"]
312326 }
313327 ]
@@ -326,6 +340,116 @@ info:
326340 ]);
327341 ```
328342
343+ ### HTTP Query Examples
344+
345+ **Query the latest block:**
346+ ```bash
347+ curl -X POST https://midnight-preview.blockfrost.io/api/v0 \
348+ -H "project_id: YOUR_PROJECT_ID" \
349+ -H "Content-Type: application/json" \
350+ -d '{"query": "{ block { hash height timestamp author transactions { hash } } }"}'
351+ ```
352+
353+ **Query a block by height:**
354+ ```bash
355+ curl -X POST https://midnight-preview.blockfrost.io/api/v0 \
356+ -H "project_id: YOUR_PROJECT_ID" \
357+ -H "Content-Type: application/json" \
358+ -d '{"query": "{ block(offset: { height: 3 }) { hash height protocolVersion timestamp transactions { hash } } }"}'
359+ ```
360+
361+ **Query transactions by hash:**
362+ ```bash
363+ curl -X POST https://midnight-preview.blockfrost.io/api/v0 \
364+ -H "project_id: YOUR_PROJECT_ID" \
365+ -H "Content-Type: application/json" \
366+ -d '{"query": "{ transactions(offset: { hash: \"YOUR_TX_HASH\" }) { hash protocolVersion block { height hash } } }"}'
367+ ```
368+
369+ ### WebSocket Subscriptions
370+
371+ Subscriptions use a WebSocket connection following the [GraphQL over WebSocket](https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md) protocol.
372+
373+ **Connecting with `websocat`:**
374+ ```bash
375+ websocat wss://midnight-preview.blockfrost.io/api/v0/ws \
376+ --protocol "graphql-transport-ws" \
377+ -H "project_id: YOUR_PROJECT_ID"
378+ ```
379+
380+ **Step 1 — Initialize the connection:**
381+
382+ After connecting, send a `connection_init` message:
383+ ```json
384+ {"type": "connection_init"}
385+ ```
386+
387+ The server responds with:
388+ ```json
389+ {"type": "connection_ack"}
390+ ```
391+
392+ **Step 2 — Send a subscription:**
393+
394+ Once acknowledged, send a `subscribe` message with your GraphQL subscription query:
395+ ```json
396+ {
397+ "id": "1",
398+ "type": "subscribe",
399+ "payload": {
400+ "query": "subscription { blocks { hash height timestamp transactions { hash } } }"
401+ }
402+ }
403+ ```
404+
405+ **Step 3 — Receive events:**
406+
407+ The server pushes `next` messages whenever new data is available:
408+ ```json
409+ {
410+ "id": "1",
411+ "type": "next",
412+ "payload": {
413+ "data": {
414+ "blocks": {
415+ "hash": "d193b2686197789ace64962eb3049c5b94c4bbf9b07da04bef034cd75d83afc4",
416+ "height": 192998,
417+ "timestamp": 1770787800000,
418+ "transactions": []
419+ }
420+ }
421+ }
422+ }
423+ ```
424+
425+ **Connecting from JavaScript:**
426+ ```javascript
427+ const ws = new WebSocket(
428+ "wss://midnight-preview.blockfrost.io/api/v0/ws",
429+ ["graphql-transport-ws", "project_id_YOUR_PROJECT_ID"]
430+ );
431+
432+ ws.onopen = () => {
433+ ws.send(JSON.stringify({ type: "connection_init" }));
434+ };
435+
436+ ws.onmessage = (event) => {
437+ const msg = JSON.parse(event.data);
438+ if (msg.type === "connection_ack") {
439+ ws.send(JSON.stringify({
440+ id: "1",
441+ type: "subscribe",
442+ payload: {
443+ query: "subscription { blocks { hash height timestamp } }"
444+ }
445+ }));
446+ }
447+ if (msg.type === "next") {
448+ console.log("New block:", msg.payload.data);
449+ }
450+ };
451+ ```
452+
329453 ### Query Limits
330454
331455 The server may apply limitations to queries:
@@ -346,27 +470,19 @@ info:
346470
347471 Many queries support offsets for pagination:
348472
349- **BlockOffset** (oneOf - provide exactly one):
473+ **BlockOffset** (oneOf — provide exactly one):
350474 * `hash`: Hex-encoded block hash
351475 * `height`: Block height number
352476
353- **TransactionOffset** (oneOf - provide exactly one):
477+ **TransactionOffset** (oneOf — provide exactly one):
354478 * `hash`: Hex-encoded transaction hash
355479 * `identifier`: Hex-encoded transaction identifier
356480
357- **ContractActionOffset** (oneOf - provide exactly one):
481+ **ContractActionOffset** (oneOf — provide exactly one):
358482 * `blockOffset`: A BlockOffset
359483 * `transactionOffset`: A TransactionOffset
360484
361- Example - fetch block at height 100:
362- ```graphql
363- query {
364- block(offset: { height: 100 }) {
365- hash
366- height
367- }
368- }
369- ```
485+ If no offset is provided, the latest result is returned.
370486
371487 ### Available Operations
372488
0 commit comments