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.
midnight-js
Tested with@midnightntwrk/midnight-js-indexer-public-data-provider 5.0.3.
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
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.