HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Modulesolana-haskell-sdk-1.3.0.0GHC2021

Network.Solana.RPC.WebSocket

Solana nodes expose a PubSub endpoint alongside the JSON-RPC one (by convention port 8900 next to the RPC port 8899; wss:// on hosted clusters). Instead of polling for a transaction's status, a client subscribes once and is pushed a notification the moment the signature reaches the requested commitment.

This module is transport-agnostic on purpose: it builds the exact bytes to send, parses the bytes received, and drives the confirmation handshake over a WsTransport that the caller supplies. The SDK therefore needs no WebSocket dependency of its own, and the same code works against plain ws:// and TLS wss:// endpoints.

Wiring it to the websockets package takes a few lines:

import Network.WebSockets qualified as WS

WS.runClient "127.0.0.1" 8900 "/" $ \conn -> do
  let transport = WsTransport (WS.sendTextData conn) (WS.receiveData conn)
  result <- awaitSignature transport (RequestId 1) (Just "confirmed") 30 signature
  print result

For wss:// endpoints, use wuss's runSecureClient in place of runClient; nothing else changes.

  • 6 types
  • 6 values

Identifiers

2 declarations
newtypenewtype RequestId
#

A client-supplied JSON-RPC request id. The node echoes it in the subscription acknowledgement, which is how a reply is matched to its request.

Constructors

Instances5Eq, Ord, Show, FromJSON, ToJSON
  • Eq RequestIdDefined in solana-haskell-sdk-1.3.0.0 · Network.Solana.RPC.WebSocket
  • Ord RequestIdDefined in solana-haskell-sdk-1.3.0.0 · Network.Solana.RPC.WebSocket
  • Show RequestIdDefined in solana-haskell-sdk-1.3.0.0 · Network.Solana.RPC.WebSocket
  • FromJSON RequestIdDefined in solana-haskell-sdk-1.3.0.0 · Network.Solana.RPC.WebSocket
  • ToJSON RequestIdDefined in solana-haskell-sdk-1.3.0.0 · Network.Solana.RPC.WebSocket
newtypenewtype SubscriptionId
#

A server-assigned subscription id, returned by a *Subscribe call and carried by every notification belonging to that subscription. Pass it to the matching *Unsubscribe request to cancel early.

Instances5Eq, Ord, Show, FromJSON, ToJSON

Requests

4 declarations

Incoming messages

4 declarations
datadata WsMessage
#

A message received from a Solana PubSub endpoint.

Constructors

Instances2Eq, Show
  • Eq WsMessageDefined in solana-haskell-sdk-1.3.0.0 · Network.Solana.RPC.WebSocket
  • Show WsMessageDefined in solana-haskell-sdk-1.3.0.0 · Network.Solana.RPC.WebSocket

The status of a subscribed signature.

Constructors

  • SignatureNotification
    • snSlot :: Slot

      The slot the notification is valid for.

    • snErr :: Maybe Value

      Nothing when the transaction succeeded at the subscribed commitment; the node's TransactionError otherwise.

    • snReceived :: Bool

      True for the early receivedSignature notification, which reports that the node has seen the transaction but says nothing about whether it succeeded. Such a notification is not terminal: the subscription stays open until the signature reaches the requested commitment.

Instances2Eq, Show

Parses one PubSub frame.

Note that PubSub notifications carry a context object holding only a slot (no apiVersion, unlike the HTTP RPC responses modelled by Context), so they are parsed here rather than through RPCResponse.

Transport

1 declaration
datadata WsTransport
#

A minimal bidirectional message transport: everything this module needs from a WebSocket connection.

Supplying this rather than a concrete connection type is what keeps the library free of a WebSocket dependency (see the module header for the websockets wiring), and lets the confirmation handshake be tested without a network.

Constructors

Confirmation

1 declaration

Subscribes to a signature and waits for its terminal notification, returning the slot it was confirmed in.

This is the push-based counterpart to confirmTransaction: the node sends the result as soon as the signature reaches commitment rather than being polled for it. Because signatureSubscribe cancels itself once that notification is sent, a successful wait leaves nothing to clean up.

Frames that belong to other subscriptions, and early receivedSignature notifications, are skipped. The whole exchange -- subscribe, acknowledge, notify -- is bounded by timeoutSeconds.

Returns the confirming slot, or Left describing a transaction that failed on-chain, a JSON-RPC error, an unparseable frame, or the timeout. Exceptions raised by the transport itself (a closed connection, for instance) are not caught.

A wait that ends in a timeout, a bad frame, or an on-chain failure may leave the subscription open, because only the terminal notification retires it. That costs nothing if the connection is about to be closed, which is the common case; a caller that keeps the connection alive should cancel it with signatureUnsubscribeRequest. Note also that this reads frames directly from the transport, so one connection supports one wait at a time — multiplexing several concurrent subscriptions needs a reader loop dispatching on parseWsMessage, which this function deliberately is not.