Blockchain.com WebSocket API

Receive real-time Bitcoin transaction notifications, new block events, and address activity over the Blockchain.com public WebSocket gateway.

TsgcWebSocketClient

The Blockchain.com WebSocket endpoint is a public JSON command channel — use the generic TsgcWebSocketClient to send op messages and receive utx/block events.

Component class

TsgcWebSocketClient

Platforms

Windows, macOS, Linux, iOS, Android

Edition

Standard / Professional / Enterprise

Connect, subscribe, parse

Open a TsgcWebSocketClient against wss://ws.blockchain.info/inv, send the JSON subscribe commands and parse the incoming utx and block events.

uses
  sgcWebSocket, sgcJSON;

var
  WSClient: TsgcWebSocketClient;
begin
  WSClient := TsgcWebSocketClient.Create(nil);
  WSClient.URL := 'wss://ws.blockchain.info/inv';

  WSClient.OnMessage := procedure(Connection: TsgcWSConnection; const Text: string)
  begin
    Memo1.Lines.Add(Text);
  end;

  WSClient.OnConnect := procedure(Connection: TsgcWSConnection)
  begin
    // Subscribe to all new bitcoin transactions
    Connection.WriteData('{"op":"unconfirmed_sub"}');

    // Receive new blocks
    Connection.WriteData('{"op":"blocks_sub"}');

    // Subscribe to a specific address
    Connection.WriteData('{"op":"addr_sub","addr":"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"}');
  end;

  WSClient.Active := True;
end;
// uses: sgcWebSocket
TsgcWebSocketClient *WSClient = new TsgcWebSocketClient(this);
WSClient->URL = "wss://ws.blockchain.info/inv";

// Hook OnMessage and OnConnect, then subscribe:
//   WSClient->WriteData("{\"op\":\"unconfirmed_sub\"}");
//   WSClient->WriteData("{\"op\":\"blocks_sub\"}");
WSClient->Active = true;

What's inside

Blockchain.com exposes a simple JSON op-channel over WebSocket — use TsgcWebSocketClient directly.

Unconfirmed transactions

Send {"op":"unconfirmed_sub"} after connect to receive every new mempool transaction as a {"op":"utx", "x":{...}} envelope.

New blocks

{"op":"blocks_sub"} subscribes to new-block notifications — one {"op":"block", "x":{...}} arrives per mined block (note the protocol may publish more than one event when a chain split occurs).

Address monitoring

{"op":"addr_sub","addr":"<bitcoin-address>"} subscribes to inbound/outbound transactions for a single address. Use "addr_unsub" to stop.

Generic WebSocket framing

Because Blockchain.com uses a plain JSON command channel, the TsgcWebSocketClient component is enough — no exchange-specific Delphi class is required.

Resilience

Configure WatchDog on the client to auto-reconnect on network drops, and HeartBeat with a TCP-level ping to keep the connection alive through NAT timeouts.

JSON parsing

Receive each frame in OnMessage, then parse with sgcJSON or your preferred JSON library. The transaction body sits under the x field of the envelope.

Specifications & references

Authoritative sources for the APIs this component connects to.

Documentation & Demos

Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.

Online Help — API_Blockchain Notes on connecting to the Blockchain.com WebSocket gateway from Delphi.
Free Trial — sgcWebSockets Download the trial package to use TsgcWebSocketClient against any public WebSocket endpoint.
Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only.
User Manual (PDF) Comprehensive manual covering every component in the library.

Ready to Monitor the Bitcoin Network?

Download the free trial and stream Blockchain.com events into your Delphi applications.