Skip to main content
Nexus serves the Midnight indexer’s GraphQL API over HTTP and WebSocket. The official Midnight SDK (midnight-js) and any other GraphQL client can use it with a Nexus API key. Requests are passed to the indexer as sent and its answers come back unchanged, so the schema is the indexer’s own (API v4).

The two URLs

Replace <network> with midnight-mainnet, midnight-preprod or midnight-preview, and use an API key created for that same network. A key reads the indexer of its own network only. The key goes in the URL because midnight-js takes two URLs and cannot set a request header. A client that can set headers may send X-Api-Key instead, on either URL, and leave the parameter out.
A URL with api_key in it is a credential. Keep it in server-side configuration, do not commit it, and remove the query string before you log the URL. Do not ship it in a web page: a browser dApp should take its endpoints from the user’s wallet. api_key is read on these two routes only.

midnight-js

Tested with @midnightntwrk/midnight-js-indexer-public-data-provider 5.0.3.
If you build a MidnightNetwork object, these are its indexer.queryURL and indexer.subscriptionURL. Nexus does not serve the Midnight node RPC, so nodeURL and nodeWsURL keep pointing at your node provider.

Plain GraphQL

The WebSocket speaks the graphql-transport-ws protocol (the one the graphql-ws library implements). Offer graphql-transport-ws in Sec-WebSocket-Protocol; Nexus answers with it. midnight-js also offers graphql-transport-ws+deflate; Nexus selects the plain protocol, so frames arrive as text. A handshake that offers only other sub-protocols is refused with 400.

What counts against your plan

No add-on is needed: the indexer is part of every plan.

WebSocket limits

These apply per API key, on top of your plan. midnight-js opens one connection per provider and sends a keep-alive every 10 seconds, far below these, and a contract’s state or events stream stays well under the data limit. A subscription that replays a long history in one go, such as wallet transactions or ledger events from an early index, can receive more than 2 MiB per second for longer than the burst covers, and is then closed. Code 4429 is final for graphql-ws: the subscription reports an error instead of reconnecting, so resume from the last position you received. If your workload needs higher limits, contact support. An open connection is also closed when its key stops being valid, checked every five minutes:

Refused requests

A refused WebSocket handshake answers with the HTTP status; ws and browsers report it as a failed connection.